Skip to content

Instantly share code, notes, and snippets.

@neelsmith
Last active February 11, 2024 15:52
Show Gist options
  • Save neelsmith/8359546 to your computer and use it in GitHub Desktop.
Save neelsmith/8359546 to your computer and use it in GitHub Desktop.
groovy: get an instance of a class from its name as a string
def objectInstance = Class.forName("NAME.AS.STRING").newInstance()
@anallely
Copy link

👍

@DanDare2050
Copy link

I'm assuming the name is fully qualified

@jairo-henao
Copy link

👍

@thamerbelfkihthamer
Copy link

newInstance is depricated since java V9. be careful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment