找到了不可转换的类型:int required:java.lang.Short

时间:2010-12-17 22:53:31

标签: java types

我得到了这个源代码,并要求编译它:它失败并显示错误“找到了无法发现的类型:int required:java.lang.Short”。

代码执行按位移位以将某些散列(我认为)值转换为整数。遇到此语句时,编译器失败“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]);

    CArs = 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;
..........

代码的原始作者发誓说它曾用于编译但无法帮助我。我知道只需编译一个类或构建一个包。

请注意,由于其大小,我从此代码段中删除了SQL查询...任何想法可能是什么问题?

2 个答案:

答案 0 :(得分:2)

将短值定义为short,而不是Short。即使getShort()方法返回包装器,它也将是autounboxed。 (事实上​​,为什么不使用int?)

答案 1 :(得分:2)

有没有理由使用对象?如果您使用原始 short 而不是 Short ,它应该可以工作。