我收到一个编译错误,说在java中编译以下代码时找不到符号' OptionalDouble'(我在这里没有提到Pants类的代码):
import java.util.ArrayList;
public class Application
{
public static void main(String[] args)
{
ArrayList<Pants> HudsonBayPants = new ArrayList<Pants>();
HudsonBayPants.add(new Pants("DKNY", Pants.pantType.RegularFit, 120));
HudsonBayPants.add(new Pants("DKNY", Pants.pantType.SlimFit, 100));
HudsonBayPants.add(new Pants("CelvinClien", Pants.pantType.StraightFit, 160));
HudsonBayPants.add(new Pants("CelvinClien", Pants.pantType.SlimFit, 175));
HudsonBayPants.add(new Pants("Buffalo", Pants.pantType.SlimFit, 80));
HudsonBayPants.add(new Pants("Buffalo", Pants.pantType.RegularFit, 90));
HudsonBayPants.add(new Pants("JeanMachine", Pants.pantType.SlimFit, 158));
HudsonBayPants.add(new Pants("Bulgari", Pants.pantType.RegularFit, 450));
OptionalDouble avg = HudsonBayPants.stream()
.mapToDouble(s -> s.price)
.average();
if (avg.isPresent())
{
System.out.println("Average pants price is: " + avg.getAsDouble());
}
System.out.println("\n");
}
}
任何帮助将不胜感激。