This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Features new in Java 7 and the fly likes Diamond Syntax Type Inference for Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Diamond Syntax Type Inference for Generics" Watch "Diamond Syntax Type Inference for Generics" New topic
Author

Diamond Syntax Type Inference for Generics

Shiv Swaminathan
Ranch Hand

Joined: Jul 21, 2010
Posts: 48

Though Generics is a great feature of Java 5, we had to also make sure that we follow some coding standards to avoid the disadvantages provided by generics. (There are places where Java compiler could not identify erroneous type erasure until run-time)

For details/examples refer the following articles:
http://www.anicehumble.com/2012/05/java-generic-type-erasure-advantages.html
http://www.ibm.com/developerworks/java/library/j-jtp01255/index.html

Does the Diamond Syntax Type Inference for Generics also have the same kind of issues hidden within or has the compiler improved to identify these errors?

SCEA EE5, CSM, PMP, IBM OOAD with UML, SCDJWS, SCWCD, SCJP 1.5
Shiv Swaminathan
Ranch Hand

Joined: Jul 21, 2010
Posts: 48

Any Pointers...help!!!

Though Generics is a great feature of Java 5, we had to also make sure that we follow some coding standards to avoid the disadvantages provided by generics. (There are places where Java compiler could not identify erroneous type erasure until run-time)

For details/examples refer the following articles:
http://www.anicehumble.com/2012/05/java-generic-type-erasure-advantages.html
http://www.ibm.com/developerworks/java/library/j-jtp01255/index.html

Does the Diamond Syntax Type Inference for Generics also have the same kind of issues hidden within or has the compiler improved to identify these errors?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29219
    
134

No. The diamond syntax is merely a shorthand in coding/typing. These two are the same



They are treated the same for the compiling process, hints to the compiler. Even before type erasure, they are treated the same. It's literally just a convenience for you.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Shiv Swaminathan
Ranch Hand

Joined: Jul 21, 2010
Posts: 48

So I think this drawback of generics is yet to be addressed in future releases...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Which drawback exactly?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Shiv Swaminathan
Ranch Hand

Joined: Jul 21, 2010
Posts: 48

I meant the original issues with generics (type erasure) as explained in these two articles:

http://www.anicehumble.com/2012/05/java-generic-type-erasure-advantages.html
http://www.ibm.com/developerworks/java/library/j-jtp01255/index.html
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

The type erasure for generics is still in place.


Mohamed Sanaulla | My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Diamond Syntax Type Inference for Generics
 
Similar Threads
Generics
confused with generics
Generics
generics
Generics