I find classreloading would be tremendous increment in productivity. I think redefining class is very limited.
Over the years we found several workarounds to keep constantly changing part of our applications in some kind of domain specific language(DSL) or in more free form like in XML or json or properties files or are using scripting language like javascript where redefining function (){}
from string is possible and overwriting previous function definition is easily possible.
My thoughts:
Annotations can be there to make a class reloadable, or make a class act as script i.e. a .java file can be treated as a DSL.
@Reloadable
public SomeReloadableClass{
}
@Script
public SomeReloadableClass{
}
Now there will be concerns that reloadable classes's references might be help elsewhere which cause memory leaks while trying to unload a class.
To overcome this there should be some constraints enforced. Although this part is hard but we can have either interface contracts, or through annotations. If required there can be a contract imposed for exports and dependencies much like OSGi descriptors but within a class using interceptors or interfaces. It should be simpler than OSGi because OSGi cares for versions dependency matching etc which are not required on a per class basis.
@Reloadable (exports='..., ...')
public SomeReloadableClass{
public start(){ ...}
public stop() { ...}
}
I feel this feature would be extremely handy, as a byproduct we can use java as configuration files, java as DSL while most parts of the program will still be a compiled monolith to be adequately performant.
A javascript program always uses javascript or json as configuration descriptor, which is again a javascript object notation. We should be able to do the same in java or in any jvm language.
Is java module system focusing on this?
Note: I feel this is not quite in a question format, rather a proposal, and in that sense its in the wrong Q-A site. I am not sure where to move, so I am thinking aloud here. Suggest where to move it.