Results 1 to 5 of 5
  1. #1
    Bojevnik is offline Member
    Join Date
    Aug 2007
    Posts
    13
    Rep Power
    0

    Default How to use <,>,== on custom classes

    Is it possible to use <>= on custom class?
    for example
    Java Code:
    ...
    CustomClass a = new CustomClass(x);
    CustomClass b = new CustomClass(y);
    if(a<b)...
    I already played with comparable and comparator interface but with no luck.
    I HATE SMURFS!!!!!

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    I did not see such a thing. What is the meaning of the operation in your mind? I mean, you can compare two integers but what can be the meaning of comparison of two classes?

  3. #3
    Bojevnik is offline Member
    Join Date
    Aug 2007
    Posts
    13
    Rep Power
    0

    Default

    You would define the meaning of comparison.
    Because that's what i thought comparabele does.

    if you would call let's say a==b, progrgam would automaticly called function
    compareTO and if result would be 0, the statement would be true otherwise it would be false.

    EDIT: Thanks for answert, but i've heard it can't be done.
    Last edited by Bojevnik; 09-28-2007 at 02:25 PM. Reason: new info
    I HATE SMURFS!!!!!

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    As far as i know, that is called operator overloading in C++ and Java does not have that. But of course instead of operator overloading, you can define your comparison with Comparable interface.

  5. #5
    remnahush is offline Member
    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Custom Avatar
    By JavaBean in forum Suggestions & Feedback
    Replies: 4
    Last Post: 01-17-2008, 12:28 AM
  2. Custom tgs in JSP
    By ravian in forum New To Java
    Replies: 2
    Last Post: 12-29-2007, 05:05 PM
  3. What are Custom Scopes in SpringFramework
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-28-2007, 12:48 PM
  4. Help with custom component
    By Falcon1 in forum AWT / Swing
    Replies: 8
    Last Post: 07-21-2007, 12:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •