开发者

inconvertible types found : int required: java.lang.Short

I was given this source code and asked to compile it: it fails with the error " inconvertible types found : int required: java.lang.Short".

The code does a bitwise shift to convert some hashed (I think) values to integer. The compiler fails when encountering this statement "s >>>= 5;"

...   try {...

    // Query data
    SelectQuery = "select "
     + "... " 
     + "from " 
     + "subscrib a, "
     + "account b "
     +"where " 
     +"a.cardid>0  "
     + "and "
     + "b.camc_card_id>0 "
     + "and "
     + "a.cardid=b.camc_card_id " 
     +"and "
     + "a.cardid >= ? and a.cardid <= ?";

    CApStmt = CAconn.prepareStatement(SelectQuery);
    // We set the card id ranges
    CApStmt.setLong(1, mincardversion[0]);
    CApStmt.setLong(2, maxcardversion[0]);

    C开发者_运维百科Ars = CApStmt.executeQuery();

    while (CArs.next()) {
     // We retrieve all columns from source table
     long SUBID = CArs.getLong(1);
     Date NEWCARDDATE = CArs.getDate(2);
     int CSSNUMBER = CArs.getInt(3);
     String ZIPCODE = CArs.getString(4);
     int SUBREGIONS = CArs.getBinaryStream(5).read();
     int CALLBACKDAY = CArs.getBinaryStream(6).read();

     /*
      * This field contains two-byte bitmap with the following
      * format: Bits 15-11 : Hour <- Bits 10-5 : Minutes <- Bits
      * 4-0 : Seconds/2
      */
     Short s = CArs.getShort(7);

     /* Bits 0-4 : Seconds (bitwise AND operation) */
     int secs = s & 0x1F;
     int seconds = secs / 2;

     /* Bits 5-10 : Minutes (bitwise AND operation) */
     s >>>= 5;
     int min = s & 0x1F;
     int minutes = min * 60;
..........

The original author of the code swears up and down that it used to compile but cannot help me. I know just enough to compile a class or build a package.

Note that I removed the SQL query from this code snippet due to its size...Any idea what could be the problem?


Define the short value as short, not Short. Even if the getShort() method returns the wrapper, it will be autounboxed. (And, in fact, why not use int ?)


Is there any reason to use an object? If you used a primitive short instead of Short it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜