Get type of a generic parameter in Java with reflection

Tags: , ,


Is it possible to get the type of a generic parameter? An example: public final class Voodoo { public static void chill(List aListWithTypeSpiderMan) { // Here I’d like to get …

Tags:

How to handle a static final field initializer that throws checked exception


I am facing a use case where I would like to declare a static finalfield with an initializer statement that is declared to throw a checked exception. Typically, it’d look like this: public static …

Java error: Only a type can be imported. XYZ resolves to a package

Tags: , , ,


I get the error: “Only a type can be imported. XYZ resolves to a package.” Someone has explained the cause here but I am not sure what I supposed to do to fix this. FYI: I am using Eclipse. I have …

Tags:

Suppress deprecated import warning in Java


In Java, if you import a deprecated class: import SomeDeprecatedClass; You get this warning: The type SomeDeprecatedClass is deprecated Is there a way to suppress this warning?

Impossible to make a cached thread pool with a size limit?

Tags: , , , ,


It seems to be impossible to make a cached thread pool with a limit to the number of threads that it can create. Here is how static Executors.newCachedThreadPool is implemented in the standard Java …

Java – find the first cause of an exception

Tags: , , ,


I need to check if an exception is caused by some database problem. I receive an Exception and check if its cause contains the “ORA” string and return that (something like “ORA-00001”). The problem …

Tags:

Growing ByteBuffer


Has anyone has ever seen an implementation of java.nio.ByteBuffer that will grow dynamically if a putX() call overruns the capacity? The reason I want to do it this way is twofold: I don’t know how …

Tags:

How can I write a byte array to a file in Java?


How to write a byte array to a file in Java?

Show padding zeros using DecimalFormat

Tags: , ,


I’m using DecimalFormat to format doubles to 2 decimal places like this: DecimalFormat dec = new DecimalFormat(“#.##”); double rawPercent = ( (double)(count.getCount().intValue()) / …

Iteratively compute the Cartesian product of an arbitrary number of sets

Tags: , , , ,


I want to compute the cartesian product of an arbitrary number of nonempty sets in Java. I’ve wrote that iterative code… public static List<Set> cartesianProduct(List<…