• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Compilation problem

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When i try to compiel

1. String a="ABC";
2. StringBuffer b=new StringBuffer("ABC");
3. a.equals(b);

It compiles fine though the result is false;

if i try to compile
4. float i=9.0
5. Float j=9.0F
6. i.equals(j); ///compilation problem

why is it so?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i is not an object, it's a primitive, so it has no methods.
a is an object (String class), with methods that you can call.

float is a primitive. Float is a class.
int is a primitive. Integer is a class.
....

You cannot call methods on primitives, as they don't have any.
 
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 nitin pokhriyal:
1. String a="ABC";
2. StringBuffer b=new StringBuffer("ABC");
3. a.equals(b);

It compiles fine though the result is false;


Have a look at the API documentation for String.equals.
[ June 20, 2007: Message edited by: Manfred Klug ]
 
straws are for suckers. tiny ads are for attractive people.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic