Solved New instance of dynamic constructor (Reflection)

Discussion in 'Spigot Plugin Development' started by jusjus112, Sep 2, 2020.

  1. Hi Guys,

    I've been struggling with something and I cannot figure out how to achieve this.
    I am basically trying to create a new instance of this class:
    Code (Java):
    public class Recipe implements Rewardable {

      @Getter // Lombok Getter
      public Material material;
      @Getter // Lombok Getter
      public byte data;

      public Recipe(Material material, byte data) {
        this.material = material;
        this.data = data;
      }

    }
    I am trying to create a new instance of this class, but since it requires constructor data it doesn't create it obviously. The problem is that every constructor that implements "Rewardable.class" is different and doesn't have the same parameter types. So it's impossible to invoke it with Objects because I don't know which Objects.

    So my question is, how can I create a new instance of a class with a dynamic constructor with the same values?

    Thanks in advance.
     
  2. You can’t
     
    • Funny Funny x 1