vendredi 20 novembre 2015

Check if constructor does exist at compile time

I am mapping a hibernate query to an object using a constructor like this :

Constructor<Product> contructor = Product.class.getConstructor(String.class, String.class, Integer.class, String.class, String.class, String.class,
                        String.class,String.class, String.class,Boolean.class);
criteria.setResultTransformer(new AliasToBeanConstructorResultTransformer(contructor));

If someone modify the constructor by adding a parameter, this code will fail but at runtime. It is possible to insure at compile time that the Contructor that we need here realy exists ?





Aucun commentaire:

Enregistrer un commentaire