This question already has answers here:
How do I print my Java object without getting “SomeType@2f92e0f4”?
                                
                                    (9个答案)
                                
                        
                                3年前关闭。
            
                    
我有类似以下内容:

List<Interval> intervals = new LinkedList<Interval>();
intervals.add(new Interval(1));
intervals.add(new Interval(2));


如何打印列表intervals?我尝试了System.out.println(intervals),但是它只是返回了[Interval@...]

谢谢

最佳答案

问题不在于打印List,而在于打印Interval

实现Interval.toString()方法。

10-05 21:34