您的位置:首页 > 编程语言 > Java开发

JAVA 强制类型转换错误提示

2016-02-20 14:18 459 查看
public float findPriceByIsbn(String isbn) {
String hql="select b.price from Book b where b.isbn=?";
float price=(float)getSession().createQuery(hql).setString(0, isbn).uniqueResult();
return price;
}

在做类型强势转换拿时将要强制转换的类型写成一般的数据类型报错Cannot cast from Object to float,

后来改为

public float findPriceByIsbn(String isbn) {
String hql="select b.price from Book b where b.isbn=?";
float price=(Float)getSession().createQuery(hql).setString(0, isbn).uniqueResult();
return price;
}

在做强制转换时,float——>Float, int——>Integer

记录错误。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: