aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compareing two values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compareing two values" Watch "compareing two values" New topic
Author

compareing two values

Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051




can i compare two double values with this method......
for example if i do like this..............

Test t=new Test();
int x=(int)t.findLarger(new Double(123),new Double(456));
or

can i compare 1 int and 1 double value............
int x=t.findLarger(123,new Double(456));


SCJP6.0,My blog Ranchers from Delhi
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Don't you try? Integer and Double class implements Comparable interface!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Abimaran Kugathasan wrote:Don't you try? Integer and Double class implements Comparable interface!



both are not even compiling.....i donot know what is the problem.........
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Your problem is not with the Comparable interface. it is with generics. Your findLarger() method is expecting two arguments of the same type, for example Double, and returning the same type (Double).
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Check the API of those two, because, they may imlement the generics type Comparable interface, in that case, Integer class' compareTo() method only accepts Integer object only, and Double class also! So better check those APIs.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Tom Reilly wrote:Your problem is not with the Comparable interface. it is with generics. Your findLarger() method is expecting two arguments of the same type, for example Double, and returning the same type (Double).




then how came this run..........

as one is int and other is String
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I tried it. The compiler generated three errors.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

phil sohar wrote:
Tom Reilly wrote:Your problem is not with the Comparable interface. it is with generics. Your findLarger() method is expecting two arguments of the same type, for example Double, and returning the same type (Double).




then how came this run..........

as one is int and other is String


We can't do it!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: compareing two values