Skip to content

Tag: java

Override generic method with more narrow parametrization

What I have: I have a generic method which I want to override: What I want: There will be few classes that extend C-class and narrow parametrization. Example: Question: How can I achieve that? EDIT: Class C has many heirs: D, F, G, H… Each of those classes has the single method f(T param). And for each …

Java Array of unique randomly generated integers

I have a method above which should generate an array of random elements that the user specifies. The randomly generated integers should be between 0 and 10 inclusive. I am able to generate random integers but the problem I have is checking for uniqueness. My attempt to check for uniqueness is in my code above…

Running jacocoReport

I’m using Gradle 1.7 and Jacoco plugin. My project uses Java and Scala plugins. When I run gradlew -i clean jacocoTestReport Report is not created and I see in the log What does it mean? Why report is not created? Answer The task will only run if coverage data is available. You can make sure of that by …

Is it fine to do logs in java class with thread id?

When we add logs in to the java class (using log4j), Is it fine to add thread id with that log messages? is it a bad practice? My idea was to add this thread id; Once we examine a log file of a multithreaded application, it is difficult to find out the correct flow using logs. (As an example, say

Create and populate TreeMap in one line

Like an array new Integer[]{ 1, 2, 3 }, can I create and populate a TreeMap using just one line? Any chances for HashMap or LinkedHashMap too? Answer There is no built-in syntax for specifically initializing maps. However, you can take advantage of a special syntax known as “double brace initialization&…

Convert string to List

I have a string with comma separated value that I am getting direclty from database. Now I want to pass that entire string to another query but the datatype required is long and i want to use in clause to get this done. Is there any direct way to do it instead of looping. Answer With guava: EDIT: With a

Are server 500 errors a security issue?

I’ve found that it’s possible to cause 500 errors on a server using curl and a faked GWT-Permutation with a POST payload. The payload is generating a java.lang.Exception on an Apache server. Does this open up a security issue? Should I report it to Google’s GWT support? To clarify the questi…

Selecting Nth-of-type in selenium

I’m trying to use By.cssSelector to grab the nth dom element with class c3 with a structure like this: Testing my CSS selectors, I’m becoming increasingly confused. This selector selects the 2nd instance of c2/c3 correctly: while: select nothing. Even worse, translating this into selenium, I seem …