How to best-effort get the ValueType of an any

I have a method that accepts any for one of its arguments (arg1) and a parameterized c3typ for another (arg2), and I would like to dynamically validate that the runtime Type of arg1 matches the parameterization of the runtime instance of arg2. Because of the any designation, arg1 is code-gen’ed as Java Object. Are there any helper methods for (best-effort) getting the ValueType of a Java Object?

1 Like

Answer (credit: @rohit.sureka):
Use c3.type.typesys.ValueType.guessType()

An example (Java) that worked for me:

public void foo(Object input) {
   ValueType inputType = ValueType.guessType(input); 
1 Like

If you aren’t using java code, and are more strictly using the type system, this also works:


1 Like