File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Ridiculous Syntax in JAVA generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Ridiculous Syntax in JAVA generics" Watch "Ridiculous Syntax in JAVA generics" New topic

Ridiculous Syntax in JAVA generics

Harshdeep Singh Saluja

Joined: Oct 03, 2009
Posts: 2

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 )

class X( public <X> X(X x){ } }
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

the constructor type will be either the X of the class generic type or the type passed to the constructor.

[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
Henry Wong

Joined: Sep 28, 2004
Posts: 20531

First, this topic has been cross-posted here...

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Ridiculous Syntax in JAVA generics
It's not a secret anymore!