Skip to content

Instantly share code, notes, and snippets.

@jarrodhroberson
Created October 8, 2014 15:51
Show Gist options
  • Save jarrodhroberson/ca0a95f091d234c5dd5e to your computer and use it in GitHub Desktop.
Save jarrodhroberson/ca0a95f091d234c5dd5e to your computer and use it in GitHub Desktop.
import com.google.common.reflect.TypeToken;
@SuppressWarnings("unchecked")
public T get()
{
final Class<T> entityType = (Class<T>) new TypeToken<T>(getClass()) {}.getRawType();
try { return entityType.newInstance(); }
catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment