Here you can find the source of getConstructorIfAvailable(Class
null
).
Parameter | Description |
---|---|
clazz | the clazz to analyze |
paramTypes | the parameter types of the method |
null
if not found
public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes)
//package com.java2s; import java.lang.reflect.Constructor; public class Main { /**/* w w w .java2 s.co m*/ * Determine whether the given class has a public constructor with the given signature, * and return it if available (else return <code>null</code>). * <p>Essentially translates <code>NoSuchMethodException</code> to <code>null</code>. * @param clazz the clazz to analyze * @param paramTypes the parameter types of the method * @return the constructor, or <code>null</code> if not found * @see java.lang.Class#getConstructor */ public static <T> Constructor<T> getConstructorIfAvailable(Class<T> clazz, Class<?>... paramTypes) { if (clazz == null) { throw new IllegalArgumentException("Class must not be null"); } try { return clazz.getConstructor(paramTypes); } catch (NoSuchMethodException ex) { return null; } } }