Skip to content

Instantly share code, notes, and snippets.

@cobratbq
Last active December 21, 2015 14:23
Show Gist options
  • Save cobratbq/c54ae053d68e9384c44c to your computer and use it in GitHub Desktop.
Save cobratbq/c54ae053d68e9384c44c to your computer and use it in GitHub Desktop.
Example 2: Object with statically defined requirement
package thirdcomponent;
import java.math.BigDecimal;
import java.math.MathContext;
public class UtilWithStatics {
// Predefined math context for use in calculation.
private final static MathContext C = MathContext.DECIMAL32;
public static void main(String[] args) {
System.out.println(calculate(BigDecimal.ONE,
BigDecimal.valueOf(3L)));
// prints 0.3333333
}
public static BigDecimal calculate(BigDecimal x,
BigDecimal y) {
return x.divide(y, C);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment