fork download
  1. import java.util.List;
  2. import java.util.stream.Collectors;
  3.  
  4. class Ideone {
  5. public static void main (String[] args) {
  6. List<Student> students = List.of(1.0, 2.0, 3.0, 4.0).stream()
  7. .map(Student::of)
  8. .collect(Collectors.toList());
  9.  
  10. System.out.println(sumScore(students));
  11. }
  12.  
  13. public static double sumScore(List<? extends Student> students) {
  14. return students.stream()
  15. .mapToDouble(Student::getScore)
  16. .sum();
  17. }
  18. }
  19.  
  20. class Student {
  21. final double score;
  22.  
  23. private Student(double score) {
  24. this.score = score;
  25. }
  26.  
  27. public static Student of(double score) {
  28. return new Student(score);
  29. }
  30.  
  31. public double getScore() {
  32. return score;
  33. }
  34. }
Success #stdin #stdout 0.08s 34496KB
stdin
Standard input is empty
stdout
10.0