jeudi 28 janvier 2021

Generate an instantiable class based on a static class reflectively

Can I (using reflection I presume?) create a class with all the same method names as java.lang.Math and each method just forwards it to Math?

E.g.

public class MyMath {
  public MyMath() {}

  public double abs(double a) {
    return Math.abs(a);
  }

  public float abs(float a) {
    return Math.abs(a);
  }

  public int abs(int a) {
    return Math.abs(a);
  }

  ...

  public double acos(double a) {
    return Math.acos(a);
  }
  
  ...

How could I generate this programmatically?





Aucun commentaire:

Enregistrer un commentaire