• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparable interface question

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Compiler says that "int cannot be dereferenced". Anyone can help me to explain this?

Thank you.
[ August 10, 2007: Message edited by: fedry kemilau ]
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Java is not pure object oriented;
behold there are primitive types(int,char,long..etc).

But every primitive can be represented as an Object using wrapper classes.
like , (Integer,Long..).

Though 1.5 JDK uses Autoboxing, It's recommended to write readable code. like this

Integer size = 3;
public void compareTo(Object){

---
---
return size.compareTo(_ _ _ _ );
}
[ August 11, 2007: Message edited by: Srinivasan thoyyeti ]
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At line #1 you attempt to invoke compareTo() using primitive variable size which as you know is incorrect. Methods must be invoked using object refrence variables if they are instance methods or using class names if they are static methods.
return size.compareTo(sizeToCompare)
Thanks
Deepak
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by fedry kemilau:
Compiler says that "int cannot be dereferenced"

int is a primitive type, and as such it has no methods.
 
Fedry Kemilau
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
owh ic, my bad. I did not realize the argument types.
thank you all.
Seems like I have to download java APIs
 
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic