• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic