java.math.BigInteger cannot be cast to java.lang.L

2019-02-05 21:16发布

I've got List<Long> dynamics. And I want to get max result using Collections. This is my code:

List<Long> dynamics=spyPathService.getDynamics();
        Long max=((Long)Collections.max(dynamics)).longValue(); 

This is my getDynamics:

public List<Long> getDynamics() {

        Session session = null;

        session = this.sessionFactory.getCurrentSession();
        Query query = session
                .createSQLQuery("SELECT COUNT(*) FROM SpyPath WHERE DATE(time)>=DATE_SUB(CURDATE(),INTERVAL 6 DAY) GROUP BY DATE(time) ORDER BY time;");

        List<Long> result = query.list();
        return result;

    }

Now I'm getting java.math.BigInteger cannot be cast to java.lang.Long. What's wrong?

7条回答
可以哭但决不认输i
2楼-- · 2019-02-05 21:42

I'm lacking context, but this is working just fine:

List<BigInteger> nums = new ArrayList<BigInteger>();
Long max = Collections.max(nums).longValue(); // from BigInteger to Long...
查看更多
登录 后发表回答