Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Covariant  RSS feed

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, In this Covariant example, At Line # 12, Are we getting Line#7 return type "Integer" (or) Line#8 return type "int" ("i" is of int type) ?
 
Saloon Keeper
Posts: 8599
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return type of the method is Integer, so that is what is returned. In this case, i is autoboxed. The main method expects an Integer and that's what it's getting.
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this code. It prints the class of the returned object.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!