File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from nikos blog(generics)

 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this code compile successfully?
1.
answer Yes, without warnings.
here why generic code + non-generic code is not generating warning?

2.
code 2 generates warning
o.k. because generic code + non-generic code is used.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first one, both are implicitly same! So no warnings!
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir,one more question from same source

here as method say() is overrided,so object type determines which method will invoked,so as child method is non generic it can hold anything(i.e. not primitive).
this code gives compiler error, why so?

Also if we put at line 16 it invokes child class say() method.
output:child
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I ask, Can you assign like this?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And for the output as child, generics only for compiler! Do you got the point, why do these methods override even though the differ the method signature?
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:If I ask, Can you assign like this?

no , parameter type should have to be same on the both sides until and unless we are using wildcards(?).
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arjun Srivastava wrote:
no , parameter type should have to be same on the both sides until and unless we are using wildcards(?).


So, that's why the compiler gives an Error!
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but as overriding is happening, so it should consider the non-generic method which can take anything
but why it is considering generic method here of parent class just because of parent reference type?
but finally it invokes child method if we use line below
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When compile time, it check the reference type, and at the time, generics also there. But at runtime, the generic and non-generic versions are same, VMI is there! {Generics only for compiler}
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:When compile time, it check the reference type, and at the time, generics also there. But at runtime, the generic and non-generic versions are same, VMI is there! {Generics only for compiler}

thanks, it is more clear now.
wonderful explanation
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Welcome, If you want to check more, decompile the class file and check the methods! You'll get it!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic