gpt4 book ai didi

java - 发现不可转换的类型 : int required: java. lang.Short

转载 作者:行者123 更新时间:2023-11-29 03:59:17 24 4
gpt4 key购买 nike

我得到了这个源代码并要求编译它:它失败并出现错误“发现不可转换的类型:需要 int: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 查询...知道可能是什么问题吗?

最佳答案

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

关于java - 发现不可转换的类型 : int required: java. lang.Short,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4475455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com