Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ridiculous Syntax in JAVA generics

 
Harshdeep Singh Saluja
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would like to bring to your notice that the information given on page 629 in book Sun Certified Programmer For Java 6 Study Guide.
In the first 'exam watch' given on the page under the heading "GENERIC DECLERATIONS".
It states that no two 'X' are related but after going through it many times, I found that 'X' (constructor argument identifier) is either same as class name 'X' so that it is a refrence to the object of that class or it ought to be same as 'Generic type declaration'.
In no way it can be different from either of the two options mentioned above.

If I am wrong please can you provide me with code which proves your point that all X are independent.


Thanking You
Harshdeep Singh Saluja
(will be a certified programmer soon )


CODE
class X( public <X> X(X x){ } }
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the constructor type will be either the X of the class generic type or the type passed to the constructor.
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, this topic has been cross-posted here...

http://www.coderanch.com/t/465061/Book-Reviews/ridiculous-syntax-GENERICS

That topic actually has a snippet from the book for those who are interested.


Two points...

A. That snippet mentions that you should get fired if you code like this...

B. I don't see any "no two X are related" in the quote. It lists the relationships which are not equal. And it was very explicit. It is not clear whether certain relationships can be inferred.

Now... having said that, I do believe the quote is wrong. The "X" of the constructor argument identifier, should be the generic type X.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic