Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Simple method but hard with generics: compareTo()

416044Feb 21 2005 — edited Nov 23 2005
I adjusted my getMaximum() method to generics to avoid the compiler warnings:
    static public Comparable<Comparable> getMaximum(Comparable<Comparable> comparable1, Comparable<Comparable> comparable2) {
        Comparable<Comparable> result = (comparable1 != null) ? comparable1 : comparable2; //init
        
        if (comparable1 != null && comparable2 != null) {
            int c = comparable1.compareTo(comparable2);
            result = (c > 0) ? comparable1 : comparable2; //comparable1 > comparable2?
        }
        
        return result;
    }//getMaximum()
But now, my other classes that call this method e.g. with 2 dates or with 2 numbers don't compile anymore. I tried
    static public Comparable<? extends Comparable> getMaximum(Comparable<? extends Comparable> comparable1, Comparable<? extends Comparable> comparable2) {
        Comparable<? extends Comparable> result = comparable1; //default
        
        if (comparable1 != null && comparable2 != null) {
            int c = comparable1.compareTo(comparable2); //compile error
            if (c <= 0) {
                result = comparable2;
            }
        } else if (comparable1 == null) {
            result = comparable2;
        }
        
        return result;
    }//getMaximum()
but this code doesn't compile:

Bound mismatch: The method compareTo(? extends Comparable) of type
Comparable<? extends Comparable> is not applicable for the arguments
(Comparable<? extends Comparable>). The wildcard parameter ? extends
Comparable has no lower bound, and may actually be more restrictive than argument
Comparable<? extends Comparable>

Comments

JustinCave
If you're familiar with nextval, I assume you are familiar with creating sequences and using sequences to populate primary keys...

You can always create a BEFORE INSERT trigger that automatically generates the primary key for the table. You would have to modify your INSERT statement to use the RETURNING clause if you want the client to have the value of the just-inserted primary key after the INSERT.

Justin
45878
You could create a trigger on the table which performs the "nextval" from a sequence table, that way your Java application does not need to do the work.
519688
use a sequence, and populate it via a "before insert for each row" trigger.

no other way.
514521
Not working..

From w/i SQLPLUS i execute this line:
create trigger dbame.p_trigger before insert on dbame.plant for each row

dbame is my oracle username
plant is the table name

SQLPLUS is looking for more information and/or a closing "tag" (not a semi-colon)

any help would be appreciated..

Thanks
Kamal Kishore
http://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg13trg.htm#431
519688
read the manuals
look for the section on table triggers
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 21 2005
Added on Feb 21 2005
15 comments
1,923 views