File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compareing two values

 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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));
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you try? Integer and Double class implements Comparable interface!
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it. The compiler generated three errors.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic