This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exam watch (page 604) Generics constructor

 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class X
{
public <X> X(X x){}
}

could anybody explain me this in detail?

Thanks in advance
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the above not the same as the following?

I just throw this in for discussion (generics are still puzzling me).
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is actual use of T and E and X in generics?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T and E are just conventions. T stands for type, and E stands for element. However, you can use valid Java identifiers for the type parameters.

I believe that the example in question was an example of what not to do. However, they are pointing out that there is no confusion on the part of the compiler if you use the same identifier for the type parameter as the name of the class and/or the name of the method.
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic