mercredi 6 juillet 2016

Determine return type of a Java expression in a String at runtime

At runtime, in my Java program, given a String, I 'd like to know the return type. For example:

  • 1 + 1 returns int
  • 1L + 1L returns long
  • 1L + 1 returns long
  • 1 + 1.5 returns double
  • 1 + 2 - 3 * 4 / 5 returns int
  • 1 / 0 returns int
  • 1 + Math.nextInt() returns int
  • 1.5 + Math.nextInt() returns double

How can I do this with the JDK runtime compiler, ECJ or any other dependency?





Aucun commentaire:

Enregistrer un commentaire