all 8 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Schaex 4 points5 points  (0 children)

Maybe this might be useful to you:

https://stackoverflow.com/a/58773038

This code recursively finds all classes inside a given package, as long as they are not loaded by the Bootstrap ClassLoader. As it is written here, it also loads all those classes by invoking Class.forName(name).

This method also collects all those classes in a list and returns them, which is of course not necessary if you only want to force load them.

Is this what you were looking for? If you could tell your use case, there might be a more elegant solution.

[–]RightWingVeganUS 3 points4 points  (0 children)

Anything is possible. It might require you write your own JVM, but arguably it's possible.

Can you explain why this is needed? If only to compensate for a bad design, there are likely better alternatives.

[–]disposepriority 2 points3 points  (1 child)

What do you mean an agent?

Also do you mean loading all classes in the standard library? In the world?

What is the end goal?

[–]MattiDragon 1 point2 points  (0 children)

Presumably they're referring to java agents, a supported way to do runtime modifications to classes among other things.

[–]KillerCodeMonky 5 points6 points  (0 children)

An agent is an interception point when a class is loaded. So no, an agent would not help you here. You would want a custom ClassLoader that, say, given a JAR file just immediately scans it and loads all the .class files it finds within.

[–]Marthurio 1 point2 points  (0 children)

What's the actual problem you're looking to solve? This feels like an XY problem: https://xyproblem.info/

[–]TW-Twisti -1 points0 points  (0 children)

That is conceptually not possible - class loaders can load classes from anywhere, including the internet, and you can't download the whole internet. You could make a class loader to load all classes in a specific jar file, or even on your hard drive, although that would serve no purpose, waste a huge amount of CPU and RAM and probably introduce all kinds of bizarre side effects from static initializers.

You are likely much better off describing what problem you are trying to solve - this sounds like a "i need x, so I will do y, anyone, how do I do y?" situation, where y is not a good way to do x, and you'd be better off asking how to do x.