Results 1 to 6 of 6

Thread: Redefining the method of interface

  1. #1
    Join Date
    Dec 2009
    Posts
    178

    Redefining the method of interface

    Hello,
    In one of my program, I use a TreeMap to stock an object of type Foo. But I need time to recover given the smallest object Foo, then I have redefined the method compares of the Comparator interface. But all of this does not work for me. Please check my code
    Code:
    Public class mtrmp extends TreeMap implements Comparator {
     
       Public mtrmp() {
          great();
       }
     
       Public Intl compares(Object obj1, Object obj2) {
          test test1 = (test) obj1;
          Foo foo2 = (test) obj2;
    		  
          / / Here I compare whether test1 <foo2 or test1> foo2 and foo2 = test1
          ....
       }
    }
    Please help me with this. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Redefining the method of interface

    Hello,
    I have a code with me , I think you should try it
    Code:
    import java.util .*;
     
    Public class mytrmp extends TreeMap implements Comparator <somegen> {
     
       Public mytrmp()
       {
          great();
       }
     
       Public Intl compares(Stamped obj1, obj2 Stamp)
       {
          ...
       }
    }

  3. #3
    Join Date
    Nov 2009
    Posts
    446

    Re: Redefining the method of interface

    Hello,
    The above is correct, I think you can alternatively try the following code.
    Code:
    Public class mytrmp extends TreeMap implements Compare {
     
       Public mytrmp() {
          great();
       }
     
       Public Intl compares(Object obj1, Object obj2) {
          System.out.System.out.println(obj1.getClass());
          System.out.System.out.println(obj2.getClass());
    
          Stamped test1 = (Stamped) obj1;
          Stamped foo2 = (Stamped) obj2;
           
          / / Here I compare whether test1 <foo2 or test1> foo2 and foo2 = test1
          ....
       }
    }

  4. #4
    Join Date
    Dec 2009
    Posts
    178

    Re: Redefining the method of interface

    Hello,
    Yes, this is true, I too use the custom of ca and c is wrong. But AC is still not working. The above post solution I have not tried all of them but the one which I have tried does not work for me. But I will not be changing the concept of the program , i mean to see that the basic working of the program will remain the same , so, i have the challenge of doing a code with keeping the same program result.

  5. #5
    Join Date
    Nov 2009
    Posts
    343

    Re: Redefining the method of interface

    Hello,
    It does not always work? Is what you would have a use case that highlights a malfunction (by curiosity ) So to complete my previous post you can Implementer tone comparator in an inner class, As a comparator generally corresponds to a particular object type. If you need more information on this then you can visit the sun's official site for java and all the syntax and the methods and the classes are cleanly described there.

  6. #6
    Join Date
    Nov 2009
    Posts
    330

    Re: Redefining the method of interface

    Hello,
    I just bore you with the terminology: we implement the methods of an interface, re ca no sense. In short, we need your object implements the interface Similar to something like the regular one and not the comparator. You must therefore provide your object method compareTo (Object o) which returns an integer:

    0 if your 2 items are similar
    < 0 if the current object is of lower order
    > 0 if the current object is of higher order

    After all the sorting work.

Similar Threads

  1. Replies: 7
    Last Post: 22-10-2011, 10:35 PM
  2. Method overriding versus method hiding in C#
    By ^MALARVIZHI^ in forum Software Development
    Replies: 4
    Last Post: 25-12-2010, 06:25 AM
  3. Is it possible to call destroy() method within init() Method?
    By Level8 in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 08:36 AM
  4. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM
  5. Redefining the size of a partition without losing data
    By Gajpal in forum Operating Systems
    Replies: 4
    Last Post: 21-11-2008, 07:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,395,813.14145 seconds with 16 queries