これの疑わしい有用性とは別に、私はこれらの線に沿って何かをすることが可能かどうか尋ねたいと思います。
class MyPrimitive {
String value;
public String Value {
get { return value; }
set { this.value = value; }
}
}
// Instead of doing this...
MyPrimitive a = new MyPrimitive();
a.Value = "test";
String b = a.Value;
// Isn't there a way to do something like this?
MyPrimitive a = "test";
String b = a;
プロパティを使用してプリミティブ型をカスタムクラスにラップし、get
andset
メソッドに検証などの他のことを実行させるのが好きです。
私はこれを頻繁に行っているので、標準のプリミティブのように、より単純な構文もあればよいと思いました。
それでも、これは実現可能ではないだけでなく、概念的にも間違っている可能性があると思います。どんな洞察も大歓迎です、ありがとう。