Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to change default generic type from E to T(Code Assist keeps autofilling generic type with E)
How to change default generic type from E to T [message #1826823] Fri, 01 May 2020 15:36 Go to next message
Andrew Lakkis is currently offline Andrew LakkisFriend
Messages: 1
Registered: May 2020
Junior Member
I've been working a lot recently with object-oriented programming in java on Eclipse, and the preferred name for generic types used in my CS class is "T", however, whenever code assist suggests a name it uses "E" as a name instead. Is there a way to change this default generic name, from E to T in preferences? I want this to apply to all future projects in Eclipse. If so can someone please direct me through it? Thank you.
Re: How to change default generic type from E to T [message #1826845 is a reply to message #1826823] Sat, 02 May 2020 07:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I think that you will find it defaults to the spelling in the declaration so to change a Collection you would need Oracle to change from Collection<E> to Collection<T>. For your own classes you have a free choice.

Many authors pick a slightly mnemonic parameter letter, so the original design was probably E for Collection-of-Element. By changing to T you subvert that clue. Of course if Thingy is very important in your application T might be sensible for a Collection-of-Thingy.

Regards

Ed Willink
Re: How to change default generic type from E to T [message #1826846 is a reply to message #1826845] Sat, 02 May 2020 10:14 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Let me add that using the same name for all type parameters can also cause a lot of confusion, like in compile errors of the kind "Type mismatch: cannot convert from T to T". We frequently get bug reports with examples that simply cannot be deciphered until we assign unique names to all type parameters. Some people even forget that there is no rule in the Java grammar saying that type parameters must have single letter names ;p
The <T> convention is a bit like naming all classes C, all methods m, and all arguments arg.
Previous Topic:The import org.eclipse cannot be resolved
Next Topic:JDT Core code assist
Goto Forum:
  


Current Time: Thu Apr 25 18:08:15 GMT 2024

Powered by FUDForum. Page generated in 0.03638 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top