• Post Reply Bookmark Topic Watch Topic
  • New Topic

General Java  RSS feed

 
Shanti sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

i am having some trouble in understanding type erasure.
i read this link. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950
but still i am not sure about the subsignature thing.
I read that
The signature of a method m1 is a subsignature of the signature of a method m2
if either

* m2 has the same signature as m1, or
* the signature of m1 is the same as the erasure of the signature of m2. "

I am playing with the below code.


This compiles fine. But if i change the return type from String to void, it gives an error.
could somebody please explain me this weird behaviour?

Thanks in Advance.

Added code tags
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As discussed here: http://www.coderanch.com/t/567818/java/java/Generics-method-overloading

it is probably a bug in the Java 1.6 compiler that lets you compile that code.

Due to erasure, those two methods have the same signature. (Return type is not part of a method's signature.) So those two methods should not be allowed to coexist in the same class at all.
 
Shanti sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use a meaningful subject line instead of "General Java" when you ask a question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!