3 ms·
In Java you could make an instance of a class doing c = Class.forName("tld.something.SomeClass").newInstance(); and if that string is created runtime, it's
by matsemann 5y ago
In Java you could make an instance of a class doing
c = Class.forName("tld.something.SomeClass").newInstance();
and if that string is created runtime, it's impossible to rule out usage of any dependency. So you basically have to tell the tools what to remove and what not to.
- geokon 5y agoOh that's cool. I'm not intimately familiar with Java, so it's interesting to see how it's done. I figured it was something like that. Coming from C++, reflection seems like a giant useless codesmell - and there are all these issues further down the line because of it. And I get the impression most Java code doesn't even rely on it
- matsemann 5y agoMost Java code actually does rely on it, but behind the scenes. So you could go years between writing any reflection code yourself, but libraries and frameworks use it to dynamically search for known stuff in the classpath and change behavior if it finds other class X, or use it to serialize to and from various formats and java objects, do stuff based on annotations etc.
- diamondo25 5y agoIn theory the same applies for JavaScript, just eval an obfuscated piece of code and the shaker is none the wiser.
- specialist 5y agoAges ago, I dimly recall debug tracing the classloader to see what is actually used. Something about troubleshooting Spring or some such. Same strategy could be used for "tree shaking"? I'll ponder how unused functions might be identified (during runtime).
- ygra 5y agoWell, there are techniques. One of the hackier ones is probably the one described here: https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for-madmen/ https://fgiesen.wordpress.com/2012/04/08/metaprogramming-for...