I’m a little confused- are you trying to propose a feature that should be added to the language itself?
If beans really bother you, you might consider taking a page out of the Calendar class’s book:
import java.util.HashMap;
import java.util.Map;
public class Bond {
public static enum BondField{
price, yield, spread;
}
private Map<BondField, Double> fieldMap = new HashMap<BondField, Double>();
{
fieldMap.put(BondField.price, 0.0);
fieldMap.put(BondField.yield, 0.0);
fieldMap.put(BondField.spread, 0.0);
}
public double get(BondField field) {
return fieldMap.get(field);
}
public void set(BondField field, double d){
fieldMap.put(field, d);
}
public double getBps(BondField field) {
return fieldMap.get(field) * 10000.0;
}
public double getPercentage(BondField field) {
return fieldMap.get(field) * 100.0;
}
}
Or you could convert the class into an immutable class, then add methods that return modified versions of the class, along with static helper methods for converting the fields to the information your want:
public class Bond {
public final double price;
public final double yield;
public final double spread;
public Bond(double price, double yield, double spread){
this.price = price;
this.yield = yield;
this.spread = spread;
}
public Bond withPrice(double price){
return new Bond(price, this.yield, this.spread);
}
public Bond withYield(double yield){
return new Bond(this.price, yield, this.spread);
}
public Bond withSpread(double price){
return new Bond(this.price, this.yield, spread);
}
public static double bpsOf(double d) {
return d * 10000.0;
}
public static double percentageOf(double d) {
return d * 100.0;
}
}
So there are other approaches, but simply using a bean is probably better for readability and maintainability.