JAVA 强制类型转换错误提示

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

记录错误。

posted @ 2016-02-20 14:18  蓝汐  阅读(1336)  评论(0编辑  收藏  举报