• Post Reply Bookmark Topic Watch Topic
  • New Topic

comparable  RSS feed

 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


here the type parameter T is translated into Comparable after compilation..then primitive types 4 3 5 are autoboxed to Integer...how the compiler knows it has to convert
primitve int (4) into particular wrapper class Integer while the Comparable interface has many subclasses like Integer




 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try some print statements like this inside the maximum method . . . which should confirm how the values are being boxed.

To find out how it is down you would have to download the compiler and examine its code (it is available somewhere, but I forget where). Remember that the compiler will attempt to box an int to an Integer, as described under "boxing conversion" in the Java™ Language specification; it then finds that Integer matches T extends Comparable, so it will allow the program to compile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!