Code being optimized when creating jar
Answered
When creating a jar I notice that some for each loops I have are optimized and changed into while loops, however I'm trying to avoid this does anyone know how to turn this optimization off?
Please sign in to leave a comment.
When jar is created the code is not optimized. javac does optimizations when your .java files are compiled into .class files. JVM also does optimizations to the code in real time (JIT).
Apparently, you can't disable javac optimizations, see https://stackoverflow.com/questions/5981460/optimization-by-java-compiler for details.
JIT optimizations can be disabled when you run your app, see https://stackoverflow.com/a/5242430/104891.
@Serge
oh interesting I didn't realize that was what was happening there,
If that's the case though do you by chance know if there is anyway to make it so when creating the jar file it doesn't convert my java files into class files and they stay in their original format of .java?
What problem are you trying to solve? Do you want to build a jar with the source files? Do you realize that you will not be able to run it?
I'm trying to create a jar file for an assignment I have, basically trying to get my code from my computer into a dropbox for my professor to read, run, and grade. I've been able to get the jar to create class files and then just copied the code into manually created java classes of the same name to run it, but that's the best I've been able to figure out using IntelliJ, and the instruction videos I've found online for creating jars in this IDE.
Why don't you just zip and share the project directory with all the files?
Actually that could probably work and be a simpler solution than what I was trying, well that works too I appreciate the suggestion.