I have a List<SubClass> that I want to treat as a List<BaseClass>. It seems like it shouldn’t be a problem since casting a SubClass to a BaseClass is a snap, but my compiler complains that the cast is impossible. So, what’s the best way to get a reference to the same objects as a List&…
bring JInternalFrame to the front
I have a JDesktopPane which contains a number of JInternalFrames. I’d like to be able to bring any JInternalFrame to the front, overlaying any other active frames. I found a number of code samples to do this, but none seem to work – the frame does NOT go on top of other active JInternalFrames. E.g…
Finding Java Enum types from code values?
We use code values in our database, and Enums in Java. When querying the database, we need to take a code value and get an Enum instance. Is it overkill to have a HashMap to avoid iteration? What would you do? Is there an easier way? Answer That’s exactly the approach I’d take to solve that partic…
javac error: Class names are only accepted if annotation processing is explicitly requested
I get this error when I compile my java program: Here is the java code (I’m running this on Ubuntu). Here is the javac command: How do I compile this program? Answer You at least need to add the .java extension to the file name in this line: From the official faq: Class names, ‘HelloWorldApp’…
How to change the decimal separator of DecimalFormat from comma to dot/point?
I have this little crazy method that converts BigDecimal values into nice and readable Strings. It however, also produces a so called grouping separator “,” that makes all my values come out like this: I do need the separator to be a dot or a point and not a comma. Does anybody have a clue of how …
Applet: Java heap space
Due to a small implementation mistake I discovered how quickly I could reach a Java heap space issue now the bug is fixed everything is fine but it did get me looking into how to solve this and I foudn multiple solution such as java -Xms5m -Xmx15m MyApp the problem is that this changes the java memory on my c…
Regular expression with variable number of groups?
Is it possible to create a regular expression with a variable number of groups? After running this for instance… … I would like to have something like m.group(1) = “c” m.group(2) = “d” m.group(3) = “d” m.group(4) = “c”. (Background: I’m parsing…
How to get the decimal part of a float?
I need to extract the decimal part of a float number, but I get weird results: Why does this happen? Why do I get those values instead of 0.65? Answer float only has a few digit of precision so you should expect to see a round error fairly easily. try double this has more accuracy but still has rounding error…
How to influence search path of System.loadLibrary() through Java code?
In a Java project, I am using a third-party library that loads some native library via I’d like to be able to influence the search path of this method from within my application, so that the user doesn’t need to specify a correct java.library.path value on the command line (this value depends on t…
Default properties of Java Annotation
What are the exact default values of two meta annotations (Target and Retention) in a user defined annotation? Answer According to the source code, none of them has a default value, which means you must provide it, whenever you use the annotation. The meaning of the missing annotation is defined in the javado…