Creating Anonymous Class with Set Name
When creating an expression for the scripting language Skript (https://github.com/SkriptLang/Skript) you would do:
I want to add a QoL class for simple expressions like
so that you don't need to spam classes for simple stuff like this.
The problem is the class name, I could return an anonymous class with the methods overriden but it will appear as Syntaxes$1 $2 $3... which would make it very hard to debug. Is there a way I can change that without ASM or anything bytecode related?
7 Replies
⌛
This post has been reserved for your question.
Hey @eren.! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Where do these class names appear that make it hard to debug? What about using the same class with a custom toString?
stack trace
If you are using JDK 22 or later, you can use the class file API instead of ASM: https://openjdk.org/jeps/466
While this is bytecode-related, I think you could create one template class and "just" replace the class name
Note that this is a preview feature in JDK 22 and 23 but it will be final in JDK 24 (will be released in March)
damn java releases so often
this probably wont be used in main project but i can make a separate library i guess
thank you
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@587604022349791274>.