Quantcast
Channel: User Tagir Valeev - Stack Overflow
Browsing latest articles
Browse All 42 View Live

Comment by Tagir Valeev on IntelliJ show "always true" hint but not "always...

@GhostCat well as IDEA Java support is a part of open source IDEA Community, anyone could dig into code and understand why it doesn't work. Though I agree that it's much easier to answer for IDEA...

View Article



Comment by Tagir Valeev on How to split odd and even numbers and sum of both...

@NoviceUser counting() returns long, so you need to change to Map<Boolean, Long>

View Article

Comment by Tagir Valeev on IntelliJ inspection: 'Method invocation may...

As IntelliJ IDEA developer responsible for this subsystem I confirm that this answer is correct. In general the idea is that foo() may probably return null elsewhere, but in this particular context I...

View Article

Comment by Tagir Valeev on How do I find usages of my class where it is used...

Please clarify your question supplying a couple of examples what do you want to find and what should not appear in the search results. Do you want to find class references or expressions of type Foo?

View Article

Comment by Tagir Valeev on Determine whether a String is a compile-time constant

Theoretically it's possible to instrument your JVM with JVMTI agent which intercepts isConst() call, check the stackframe, finds the callsite, loads the bytecode and checks whether there was an LDC...

View Article


Comment by Tagir Valeev on Java assertions - $assertionsDisabled vs...

This is not the reason. ifeq with $assertionsEnabled would work just as fine.

View Article

Comment by Tagir Valeev on What are the compatibility risks of replacing...

Re: Why do you think the retention policy is CLASS -- because that's what in the question. Re: Just in case, even CLASS requires to keep annotations on the class path -- 1) for compilation, not at...

View Article

Comment by Tagir Valeev on Mark method as deprecated without changing its...

@StefanPaulNoack in recent IDEA versions this option is available on method declaration only, so you should go to declaration (Ctrl+B) first. This was done to avoid accidental annotations (see...

View Article


Comment by Tagir Valeev on Why is there a "==" inside String.equals?

@Lii The @HotSpotIntrinsicCandidate marking is just a hint for developers who would like to make a given method an intrinsic (or it's already made). This doesn't actually mean that the method is...

View Article


Comment by Tagir Valeev on Why hash maps in Java 8 use binary tree instead of...

@AnmolSinghJaggi it won't work if the hashCode is exactly the same. And in case of targeted DoS attack it's quite easy to generate e.g. string keys with exactly the same hashCode.

View Article

Comment by Tagir Valeev on A warning is shown when Optional.isPresent and...

@FelipeMosso this should work with JUnit asserts. Please file a YouTrack issue providing the complete code sample.

View Article

Comment by Tagir Valeev on Why is Files.list() parallel stream performing so...

@lwpro2 it sees that the estimated size of the right part is much much bigger than the estimated size of the left part, so it doesn't even try splitting the left part anymore. And the right part (that...

View Article

Comment by Tagir Valeev on Why does Stream#toList's default implementation...

As of List.of version, it won't tolerate null elements in the stream. Actual toList() tolerates them.

View Article


Comment by Tagir Valeev on Why stream created with Spliterators is not being...

The advice to specify imprecise size is incorrect. Spliterators.spliterator accepts the exact size, rather than estimation, and subsequent stream operations may trust it. E.g., replace stream with...

View Article

Comment by Tagir Valeev on How to convert an Optional to an OptionalInt?

@M.Justin haha, indeed! I edited the answer to remove outdated hopes :-)

View Article


Answer by Tagir Valeev for Why the HashMap#resize implementation is so complex?

At resize, every bin is split into two separate bins. So if the bin contained several linked items, you cannot move all of them into the single target bin based on the hash of the first item: you...

View Article

Answer by Tagir Valeev for How to sort Map by value in desc and key in...

Create a comparator chain using thenComparing:Map mp = map.entrySet().stream() .sorted(Collections.reverseOrder(Map.Entry.<String, Integer>comparingByValue())...

View Article


Answer by Tagir Valeev for Generic type argument in java generics

You need a separate type argument for a Result interface. Something like this:interface Result<T, R, W extends Wrapper<T, R>> { R getResult();}Now you can use W inside the result to...

View Article

Answer by Tagir Valeev for performance, internal working and order of...

Current Stream API implementation processes elements one-by-one without intermediate buffering, unless it has to. For sequential stream only sorted() operation is a "full barrier" operation, so for...

View Article

Image may be NSFW.
Clik here to view.

Answer by Tagir Valeev for Run JUnit test with IntelliJ

You can specify the same -D parameters in Run configuration settings. Press "Run" (Alt+Shift+F10 on Windows, Ctrl+Alt+R on Mac), select your run configuration, Right arrow, Edit:Then specify all -D...

View Article

Answer by Tagir Valeev for Java assertions - $assertionsDisabled vs...

This is actually done for a reason, not merely for something like a more compact bytecode or faster condition execution. If you look at the Java Language Specification, §14.10, you will see the...

View Article


Answer by Tagir Valeev for Alternative to MoreObjects in Java 8

I don't see any reason to use this toStringHelper even prior to Java 8. The plain implementation is not longer:@Overridepublic String toString() { return getClass().getSimpleName()+"["+"userId:...

View Article


Answer by Tagir Valeev for How can I initialise a static Map?

Map.of in Java 9+private static final Map<Integer, String> MY_MAP = Map.of(1, "one", 2, "two");See JEP 269 for details. JDK 9 reached general availability in September 2017.

View Article

What are the compatibility risks of replacing METHOD/FIELD/etc. targets with...

I have a Java package that contains annotations used by external clients. The package appeared before Java 8, so historically these annotations have targets ElementType.METHOD, ElementType.FIELD,...

View Article

Answer by Tagir Valeev for Integer.toBinaryString() not correctly converting...

According to Java Language Specification, §3.10.4:Character literals can only represent UTF-16 code units (§3.1)When you call Integer.toBinaryString(), the char literal is implicitly converted...

View Article


Answer by Tagir Valeev for Improve Intellij Code Inspection for may produce...

Disclosure I'm IntelliJ IDEA developer responsible for this subsystemNo, it's not possible now. There's no better solution than possible workarounds you already listed, assuming that you cannot change...

View Article

Image may be NSFW.
Clik here to view.

Answer by Tagir Valeev for Can IntelliJ convert my old string concatenation...

Disclosure: IntelliJ IDEA developer is here.Currently, IntelliJ IDEA only suggests converting the complete literal concatenation into the text block. Here, however, you have a concatenation that...

View Article

Answer by Tagir Valeev for CERK07- SPOJ - bitmask in bfs

The result of (umask & 0x2) expression is either 0 or 2. It cannot be 1, hence IntelliJ IDEA warns you about this. Similarly (umask & 0x4) is either 0 or 4 and (umask & 0x8) is either 0 or...

View Article

Answer by Tagir Valeev for How to force max to return ALL maximum values in a...

I implemented more generic collector solution with custom downstream collector. Probably some readers might find it useful:public static <T, A, D> Collector<T, ?, D> maxAll(Comparator<?...

View Article



Answer by Tagir Valeev for Is there a common Java utility to break a list...

In case you want to produce a Java-8 stream of batches, you can try the following code:public static <T> Stream<List<T>> batches(List<T> source, int length) { if (length <=...

View Article

Answer by Tagir Valeev for How do I read / convert an InputStream into a...

For completeness here is Java 9 solution:public static String toString(InputStream input) throws IOException { return new String(input.readAllBytes(), StandardCharsets.UTF_8);}This uses the...

View Article

Answer by Tagir Valeev for Java Streams - Get a "symmetric difference list"...

Something like this may work:Stream.concat(bigCarList.stream(), smallCarList.stream()) .collect(groupingBy(Function.identity(), counting())) .entrySet().stream() .filter(e ->...

View Article

Answer by Tagir Valeev for Does the JDK provide a dummy consumer?

No, JDK does not provide dummy consumer as well as other predefined functions like dummy runnable, always-true predicate or supplier which always returns zero. Just write t -> {}, it's anyways...

View Article


Strange "!*" entry in LocalVariableTypeTable when compiling with Eclipse...

Let's compile the following code with ECJ compiler from Eclipse Mars.2 bundle:import java.util.stream.*;public class Test { String test(Stream<?> s) { return s.collect(Collector.of(() -> "",...

View Article

Answer by Tagir Valeev for IntelliJ Refactor to pull variable definition...

Since IntelliJ IDEA 2021.3 (EAP builds are already available) it's possible just to complete the variable outside of try block to bring it into the scope:try { IndexResponse indexResponse =...

View Article

Answer by Tagir Valeev for Why stream created with Spliterators is not being...

There was a flaw in Spliterators.spliteratorUnknownSize() implementation. I fixed it in Java 19, see JDK-8280915. Since 19-ea+19-1283 early access build the problem is not reproduced anymore, your code...

View Article


Answer by Tagir Valeev for Parallelism with Streams created from Iterators

There was a flaw in Spliterators.spliteratorUnknownSize() implementation. I fixed it in Java 19, see JDK-8280915. Since 19-ea+19-1283 early access build the problem is not reproduced anymore,...

View Article


Answer by Tagir Valeev for Trying to read from the console in Java

Normally, the Console object requires a valid tty provided by an operating system, but IntelliJ IDEA output window does not provide one. It's not very trivial to do this in OS-independent way. Not only...

View Article

Answer by Tagir Valeev for How to escape the (hash) # sign in a GitHub...

Add an extra space after ### C\#.

View Article

Answer by Tagir Valeev for How to zip two Java Lists

Here's Java-8 solution using the Pair class (like in @ZhekaKozlov answer):public static <A, B> List<Pair<A, B>> zipJava8(List<A> as, List<B> bs) { return...

View Article

Answer by Tagir Valeev for How to write code in Java 11, but target Java 8...

There's a tool called Jabel created by @bsideup, which allows you to do this. It pretends to be an annotation processor so it could be plugged into javac. However, it doesn't do any actual annotation...

View Article


Answer by Tagir Valeev for Code coverage finally block

In the Java bytecode (at least since Java 1.6) there's no special construct for the finally block, so it is actually duplicated many times. For example, consider the following method:public static void...

View Article
Browsing latest articles
Browse All 42 View Live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>