标签:
public class StringUtil { public static Optional<Double> toDouble(String s){ try{ return Optional.of(Double.parseDouble(s)); }catch (Exception e){ return Optional.empty(); } } }
Student student = new Student(); StringUtil.toDouble(gradeField.getText()).ifPresent(grade->student.setGrade(grade));
标签:
原文地址:http://www.cnblogs.com/HertZSang/p/4836239.html