Skip to content

Util ​

com.jsmacrosce.Util

Provides numeric-value conversion for reflective calls and proxy argument or return values.

js
const Util = Java.type("com.jsmacrosce.Util");  
const Integer = Java.type("java.lang.Integer");  
const Double = Java.type("java.lang.Double");  
Chat.log(Util.tryAutoCastNumber(Integer.TYPE, Double.valueOf(3.75)));

Constructors ​

new Util ​

new Util()#

Methods ​

tryAutoCastNumber ​

static tryAutoCastNumber(Class<?> returnType, Object number): Object#
Converts a Number to the wrapper for a supported primitive or boxed target. Supports int, float, double, short, long, char, and byte targets; matching wrapper values are returned unchanged. Numeric conversions use the corresponding Number conversion method, so narrowing conversions may discard or truncate value. For char, the value is converted through Number.intValue() and cast to char. Unsupported targets, including null, return number unchanged; Boolean is not converted. For a supported target, null input or an input that is neither the matching wrapper nor a Number fails during conversion.

Parameters:

  • returnType: primitive or boxed target class
  • number: value to convert
Returns: the converted wrapper, or the original value when no conversion applies