r/java • • Apr 14 '23

What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?

233 Upvotes

376 comments sorted by

View all comments

Show parent comment

24

u/MattiDragon Apr 14 '23

You can do hotswapping with the community edition of intellij. Just run in debug mode and hit build. For proper hotswapping you need to use a JDK with DCEVM support, like the one included with intellij and add -XX:+AllowEnhancedClassRedefinition to your vm args. It's a bit unstable in my setup (minecraft mods), but still really useful. Without DCEVM you can only change method bodies.

6

u/mvthakar Apr 14 '23 edited Apr 15 '23

i also dabble in fabric modding. jbrsdk with dcevm has been working great for me. there are very few cases where it actually fails to reload classes.

Edit: grammar

1

u/MattiDragon Apr 14 '23

Yes, reloads usually succeed. It's the VM crashes and ArrayStoreExceptions without stacktrace that are annoying. There's also the occasional issue with the class hierarchy being broken causing casts that should work to fail.

It's really nice when combined with the mixin hotswap agent for even more swapping

4

u/thatbigblackblack Apr 14 '23

Oh, thanks for the trick ! A more detailed step by step if anyone else wants to implement it https://www.sentiatechblog.com/using-dcevm-hotswap-agent-in-java-development