This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You can, to some degree, use the generic parameter which you called 'T'. That is, you can do something like this in myMethod:
You can not, however, instanciate objects or arrays of T, or get the class of T. Unfortunately, java has what is called type erasure. Effectively, this means that while the compiler will check the type of MyClass at compile time, the information will be lost at runtime. This has been criticized by a lot of java developers. Java 8 will probably be able to preserve the type parameter at runtime, as do other JVM languages like Scala, but with pure Java 6/7, you can't do what you want.
Cristian Daniel Ortiz Cuellar
Joined: Feb 02, 2011
Alexander Kober wrote:You can, to some degree, use the generic parameter which you called 'T'. That is, you can do something like this in myMethod: