彼の AutoBean を生成したいクラスがあります。
Example.class :
public static class Example implements Serializable {
public Example2 example2 = new Example2();
public static BigDecimal calc(BigDecimal dec){
return dec != null ? dec: BigDecimal.ZERO;
}
public static class Example2 implements Serializable {
public BigDecimal value1 = BigDecimal.ZERO;
public BigDecimal value2 = BigDecimal.ZERO;
public BigDecimal getSum(){
return calc(value1).add(calc(value2));
}
}
}
AutoBean の例:
public inteface Example {
@PropertyName("example2")
public Example2 getExample2();
BigDecimal calc(BigDecimal dec);
}
私はこれをやろうとします
AutoBean の例 2 :
public interface Example2 {
@PropertyName("value1")
public BigDecimal getValue1();
@PropertyName("value2")
public BigDecimal getValue2();
BigDecimal getSum();
}
関数が実装されているExample2Categoryもあります。
しかし、value1またはvalue2を取得しようとすると、エラーが発生します:
TypeError: null のプロパティを読み取れません
クラス表現のような初期化された値がないために、これが起こったと思います。この解決策を試してみましたが、うまくいかないようです。
では、Example2 クラスの AutoBean を init 値で表すにはどうすればよいでしょうか?