text
stringlengths
46
37.3k
title
stringlengths
12
162
Java : I 'm trying to experiment with lambdas for fun . I created a functor which allows the composition of a lambda . But , the means of composition only allow a linear transformation , and does not allow branching.The idea is that I know I will have , in the future , an effectively immutable state data structure . I ...
Branching when composing lambdas from other lambdas
Java : I got the following structureNow , I have a list of those points defined.The data does not matter at all , just a list of points ( the above is just an easy and quick example ) .How can I transform this list to a array of doubles ( double [ ] array ) in a Java 8 way ? <code> public class Point { private final do...
Converting Pair of Double into a double array
Java : I have a List < Map < String , String > > such as : My expect result is to generate a new List map , which is grouped by date , and all the entry set in the same date would be put together , like : I tried with the following method , but always not my expect result.Some Additional Comments for this problem : I w...
Java 8 stream grouping a List < Map < > > by the same < Key , Value > to a new List < Map < > >
Java : Possible Duplicates : Can not refer to a non-final variable inside an inner class defined in a different method Why inner classes require “ final ” outer instance variables [ Java ] ? The above code works fine.I want to know why does the compiler give an error if I remove the final keyword from String z . What d...
Java Inner Classes
Java : I am having an issue with a hashmap . In my hashmap method i want to have two or more keywords as a key , oppose to having one . For example I want the user to input some sentence containing two or more keywords assuming `` professor name '' is a keyword . For exampleAnd the user enters `` what is the professor ...
Understand two or more keys with Hashmaps
Java : I wanted to learn something more about generics and to do so I decided to write a simple application . It allows to retrieve list of all entities using CriteriaQuery.First of all , I tried to generify code by using type parameter ( T ) . However , my code will not even compile . Why ? I 've come up with another ...
Avoiding unchecked casting using generics
Java : Consider the following set of expressions : An attempt to compile this will fail on line /*1*/ with the error : both when using OpenJDK 1.8.0 ( Ubuntu ) or Oracle JDK 1.8 ( Windows ) .However , Eclipse 4.5.0 ( Mars ) compiles this without any error and it results in : From this you can see that the line /*1*/ of...
Is 'T.super ' a legal expression as per JLS ?
Java : I have a table which I need to query , then organize the returned objects into two different lists based on a column value . I can either query the table once , retrieving the column by which I would differentiate the objects and arrange them by looping through the result set , or I can query twice with two diff...
Better to query once , then organize objects based on returned column value , or query twice with different conditions ?
Java : I 'm developing a project ( in Java 8 ) that involves the simulation of logic circuits . The circuits are described in an input file that I 'm parsing with ANTLR v4.Using ANTLR 's visitor classes , I build up a Composite structure that stores all of the necessary components to simulate the circuit.Afterwards , I...
Why would calling a dummy function fix a bug ?
Java : I would like to know how ( if it is possible ) could I program a Java class using a data layout Array of Class , for example : but internally the data would be store as a layout of Class of Arrays like this : My objective is that the programmer could programed in a more intuitive style like the first one , but i...
How to automatically convert from Array of Classes to Class of Arrays
Java : I would like to modify the following method so its arguments can be of any type that implements the Comparable interface . The method ’ s return type should be the same as the type of its parameter variables.So in modifying it , I could just use < T extends Comparable < T > > , but how would I go about making th...
Modifying a method so the arguments can be any type that implements Comparable
Java : This message pertains strictly to Java . If a method is in a superclass there are two ways the method could be called : Is there any harm in always doing the latter ? As a coding style I prefer the latter because it 's clear at a glance where the method call is coming from . Are there any circumstances where 'su...
Is there any harm in using super when not needed ?
Java : I 'd like to write some troubleshooting code which i can easily remove from later non debug versions of my program . I came up with : Is Java smart enough to drop the if statement from the final bytecode if debug==false ? Is there a better practice to achieve the goal of keeping debug code out of the final versi...
How smart is Java about if statements with final variables
Java : Edit : this question is malformed to the extent that I can not really fix it , and is a bug somewhere in my project . The root cause of my problem is that myLambda.getClass ( ) should not throw ClassNotFoundException , and the lambda works as expected.Given the class of an interface And a lambda instanceHow can ...
How to determine if JDK8 lambda can be assigned to type ?
Java : In this book , it says : A limitation of Arrays.asList ( ) is that it takes a best guess about the resulting type of the List , and does n't pay attention to what you are assigning it to.The book is Thinking in Java By Bruce EckelHowever , the following code is working fine , contrary to code shown in this book ...
The limitation of Arrays.asList ( ) is not true in Thinking in Java 4th Edition
Java : I have a class : When I declare a Generic with wildcard and call getList method , the following assignment is illegal.This seems odd to me because according to the declaration of Generic , it 's natural to create a Generic < T > and get a List < List < T > > when call getList.In fact , it require me to write ass...
Why is this generic assignment illegal ?
Java : I 'm programming in Java for only a few months so I 'm not that experienced with Java ( some tricks and the basic things I should know though ) .I got a problem which may be obvious but I do n't see it.This is an extract from my code.How can this be true ? These are two separate objects . I do n't get it.The foo...
Two newly created objects seem to refer to the same address
Java : I am working on a Enterprise application . I am facing some issues while running application in multithreaded environment . I am writing a program in which there is a variable whose value is getting updated ( incremented ) at very fast rate ( for example 10000 updates/persecond ) . A loop runs for certain iterat...
Java Multi-threading : Unexpected result
Java : According to the Java Language Specification , java.lang.Object is the root of Java 's inheritance hierarchy . Unlike C++ or Objective-C , programmers can not specify their own root superclasses . Because of this , I figured it was impossible to actually define java.lang.Object in Java itself . To my surprise , ...
How is it possible that java.lang.Object is implemented in Java ?
Java : I am given some classes that are unknown to me . Some of them are shown as an example : The task is to redesign method signature types if needed and to add implementation . The bake method should conform to the following : Create objects of class Bakery or any subclass of it according to class argumentFlag compi...
Java generics and reflection : class loading
Java : I 'm trying to build a project using JDK 9 , as using the -- release argument to javac means it can build for older versions without needing the corresponding JDK/JRE installed . I need to support Java 6 so my preexisting set up requires Java 6 for the bootstrapClasspath and a further JDK 8 or 9 for gradle and t...
Targeting Java 6 with Java 9 JDK gives warnings
Java : I have a base class ShapeManager with a list of shapes which I want toenumerate ( ) . Then there is a specialization ColoredShapeManager which wantsto process specialized ColoredShapes instead of Shapes : I am unsure whether ShapeManager should share shapes : List < Shape > with itschildren This seems flawed sin...
Sharing a list of base type with children
Java : I am in the midst of creating an online contact management tool for users to manage contacts and clients . I am trying to develop a solution where the user will add a BCC or CC in any email client like this : and my app will grab the recipients to address information email , name , etc and my backend script will...
create an email drop box with php , javascript etc
Java : I was trying create an array of a collection as follows.but it gives me an error - > generic array creationcan anybody explain me why is it ? <code> ArrayList < Integer > ar [ ] =new ArrayList < Integer > [ 50 ] ;
Can we have an Array of a collection ?
Java : Bear with me ... I do n't think this is too subjective but maybe I 'm wrong.Recently I wanted to factor out some repetitive code which drew a custom Bitmap background on our BlackBerry app . ( This question is not really about BlackBerry though , so I 'll provide some details here about the BB GUI so that non-BB...
Is this idiomatic Java ?
Java : I have a loop that is running until the user clicks a ready button , and then it starts the the loop inside the if-statement , but it only works it there is a print statement before it . Does it have to do with how the Rule Set is static ? The Button works no matter what , but it only enters the loop if the prin...
If statement only entering if print before
Java : A Local Cluster from a web classloaderI 'm trying to run a local cluster from a web container ( yes , it 's only for dev & testing purposes ) and am having difficulty with classloaders.Direct approachWhen I do it the easy and recommended way , I get rewarded withThis is because the classloader used to load and i...
Run a local cluster under a nondefault classloader
Java : I 've been trying to figure out how to find a O ( n ) time complexity algorithm to solve the following in Java : We are given an input pair with a start point and end point , and we have to construct a path such that the start of one input matches the end of another input ( in this case , alphabetically ) EX : i...
Path reconstruction with Hashing ?
Java : Chrome is not stable on my Jenkins . When I run build 5 times , it runs 1 - 2-time success , and the other 3 times I have the above error.Snapshot of the error : Code for Chrome : Some steps I have already taken : Provided 777 permission to google chrome and chrome driverSet : Start Xvfb before the build , and s...
org.openqa.selenium.WebDriverException : unknown error : Chrome failed to start : crashed using ChromeDriver Selenium in Jenkins on Ubuntu 18.04
Java : I have this Java problem , which I suspect it relates to a higher-level algorithm , but my searches have n't been able to come up with anything practical.You construct an array as follows : Basically , Ai , j = Ai-1 , j-1+Ai-1 , j . It 's supposed to return the element at index ( l , c ) : for ( 4 , 1 ) it shoul...
Calculate element in matrix incrementally , using neighbors
Java : I want to create a big array , and want to try out some lambda , but for some reason that : wont work , even that : dose not work.The compiler error is : Type mismatch : can not convert from boolean to Tand : The method setAll ( T [ ] , IntFunction ) in the type Arrays is not applicable for the arguments ( boole...
Arrays.setAll wont work with boolean
Java : I 've been trying to take a sub list of a list , reverse it , and place the reversed list back into the starting position . For example , say we have the list [ 1 , 2 , 3 , 4 , 5 , 6 ] , then reversing from index 2 to index 4 would give [ 1 , 2 , 5 , 4 , 3 , 6 ] .I 've written some code for this , however it giv...
Why does List.addAll of a reversed subList of the list cause a ConcurrentModificationException
Java : This is a continuation of this questionSpring WebMvcTest how to mock Authentication ? I 'm trying to test a controller method in Spring-boot that receives an Authentication object as parameter . The controller is a RestController with @ CrossOrigin annotation . The method looks like this : As you can see i get t...
Spring-Boot WebMvcTest : How to test controller method with Authentication object parameter ?
Java : I am performing some actions on a stream and returning an array list . This is working without a problem but I need to do a final step to add an element if the array list is empty ( nothing to do with options / nulls just part of the requirement ) My way is a bit clunky and I wondered if it can be done in the st...
Add a default item to a stream collection
Java : I 'm pretty new to the Java World ( since I 'm writing primary in C/C++ ) . I 'm using maps in my apps.Since java.util.Map is abstract I need to instantiate it 's implementation . Usually I use HashMap like : But in java docs I found many other implementations , like TreeMap , LinkedHashMap , HashTable , etc . I...
java : maps zoo , what to choose
Java : I want to sort a map using Java 8 streams and return a list of its key.Map signature is : and the data will be like [ 1=6 , 5=13 , 2=11 ] There are two conditions on which I have to sort and return a list of keys.If all the values of the keys are different , then sort and return a list based values in descending...
How to define custom sorted comparator in java 8 Stream to compare on the key and the value
Java : In my Java application a small put important feature is to be able to rename audio files based on their metadata ( e.g album/artist -title ) and the mask is specified using Javascript , this makes for a very flexible and powerful renaming feature . I knew Javascript was being deprecated but it now seems it is ac...
How can I continue to use Javascript in Java 15 onwards
Java : In the code below , the instance variable called `` x '' inside subclass `` B '' hides the instance variable also called `` x '' inside the parent superclass `` A '' .In the code below , why does println ( z.x ) display the value of zero ? Thanks . <code> public class A { public int x ; } public class B extends ...
Instance variable hiding with inheritance
Java : I 'm trying to use Java Opencl from within jruby , but am encountering a problem which I ca n't solve , even with much google searching.when I run this code using : jruby test.rbI get the following error , when the last line is uncommented : Just wondering whether anyone has an idea on how to solve this problem ...
Trouble using java class within jruby
Java : While testing , I upgraded my Junit to 5.0 ( Thus replacing some of my assertTrue ( ) methods with the new versions ) . After doing so , I found one of my tests did n't compile . I reduced the issue down to plain old java with no junit or other dependencies . The result is the following code which will not compi...
Java can not compile generic lambda argument unless parameter type is specified
Java : Sample code to demonstrate the failure : Here is the Error ( not Exception ) I see : I am using 32-bit Java 8 ( v1.8.0_60 ) with Google Guava v19.0 . My Google-Fu tells me Google Guice is the root cause , but lacks credible explanation . ( This is part of a much larger project that also includes Google Guice v3....
Why does Google Guava 's ArrayListMultimap clear method throw IllegalAccessError when called by method reference ?
Java : I was just trying something with try-catch and this code : I understand Error will not be caught by the catch block above , but the finally block will be executed , and then the JVM will terminate.But when I try to run the program many times , I get different outputs : C printed before the stack trace : or C pri...
In case of Error , program shows unexpected behavior
Java : Testing some things out I tried o make an enum in which every one element in a enum have a different class inside.Take for example : If i try to put a public modifier before any class , the Modifier not allowed here shows up . I am not quite sure why this would be . I can not instantiate those classes outside th...
Why cant I make an enum 's inner class public ?
Java : I have a question about using generics with collections . We know that the above line means that ArrayList al is restricted to hold only integers . So the following line gives a compilation error : But I do n't understand what the below line means , Where we do n't give ArrayList < Integer > at the left side whi...
Collection with generics
Java : I have these statements : This compiles perfectly . And outputs But : outputsI did some research on this topic . I read the documentation , and it says : This method can not handle supplementary characters . To support all Unicode characters , including supplementary characters , use the isJavaIdentifierStart ( ...
Is \u65549 a valid Java identifier ?
Java : I 'm reading on Joshua Bloch 's Effective Java , 2nd edition , Item 11 : Override clone judiciously . On page 56 , he is trying to explain that when we override clone ( ) for some classes ( like collection classes ) , we must copy the internals of it . He then gives the example of designing a class Stack : He cl...
Effective Java claims that elements.clone ( ) suffices
Java : Consider the following Java function : This does not work , since the type captures of cl and ls are not unified and can , indeed , refer to different types . Had this function compiled , I could have called it as foo ( NullPointerException.class , new List < SecurityException > ( ) ) , which would have been ill...
Can captures in Java generics be unified in type declarations ?
Java : Here 's the context if it 's necessary for any answers . I 'm building an engine in which I 'm going to make a videogame . It involves a 96 x 54 ( columns x rows ) table of letters , to keep an even spacing between them . Because of this , it would be very helpful if any solutions could be as least resource inte...
Allow text in multiple JLabels to overlap
Java : Consider this method : As you can see the set is creating a new TreeSet with a custom comparator . I was wondering if it makes any difference from a performance/memory/garbage collection/whatever point of view , if I were to do this and instead having polluted the outer space : The reason I am asking , is that I...
Is extracting to static final necessary for Java optimization ?
Java : By default , Java does Binary Numeric Promotion for primitives , but does not do the same thing for objects . Here 's a quick test to demonstrate : Output : This is obviously correct behavior - an Integer is not a Long . However , does there exist a `` value equals '' for Number subclasses that would return true...
Is there a number `` value equals '' ?
Java : The following code measure the time it takes for 100 invocations of the method handle ( Object o ) from the interface Handler ( Yes it 's bad quality profiling ) : The fact is that if the LinkedList contains only one kind of Handler , for example SuperHandler , the execution time is smaller than if they were 2 ,...
Java - LinkedList - Performance decreases with the number of different classes in it
Java : In the JSR-133 , there are two example that state presumably correctly synchronized programs.The first example is given by figure 6 where : Then , thread 1 modifies the state by : and thread 2 modifies the state by : The author states that this program is correctly synchronized,However , there is an execution of...
How to understand JSR-133 Happens-Before is too Weak Figure6/7
Java : Java has two ways of checking whether two booleans differ . You can compare them with ! = , or with ^ ( xor ) . Of course , these two operators produce the same result in all cases . Still , it makes sense for both of them to be included , as discussed , for example , in What 's the difference between XOR and NO...
Is there a useful difference between ( p ^ q ) and ( p ! = q ) for booleans ?
Java : Benchmarking the following Java code using jmh : Using mvn package & & java -XX : -UseCompressedOops -XX : CompileCommand='print , *.testMethod ' -jar target/benchmarks.jar -wi 10 -i 1 -f 1 , I was able to get the assembly , and if we focus on the one from C2 ( as shown below ) , we can see that both cos and sin...
JVM JIT method recalculate for pure methods
Java : I have a string that looks like this : [ `` 1011000 '' , `` 1000010 '' , `` 1001101 '' , `` 1000011 '' ] .My argument is coming from elsewhere so it needs to be this way.I need to typecast this to a real byte array.Here 's my method : It does n't work , however . Complains about inconvertable types String to byt...
Help typecasting a String Array of bytes to actual bytes
Java : I 'm trying to read N items from a RingBuffer using readManyAsync but It 's always returns an empty resultSet . If I use readOne I get data.I 'm using the readManyAsync as the documentation specify . There is another way to do that ? Enviroment : Java 8Hazelcast 3.5.3Example : Output : <code> Ringbuffer < String...
Hazelcast Ringbuffer readManyAsync returns Empty Results
Java : I 've got one ClassLoader for trusted application code and a seperate ClassLoader for user-submitted ( untrusted ) code.I want the user-submitted code to be restricted by the Security Manager . How do I check the caller origin from within the SecurityManager ? See the psuedocode : What I 've tried already : Stac...
How to check caller class origin in SecurityManager ?
Java : In the below code , the line System.out.println ( sumInteger ( bigs ) == sumInteger ( bigs ) ) ; displays as false . But when again we compare the another Integer wrapper classes System.out.println ( bc == ab ) ; , it returns true . Why is the comparison of wrapper classes false in the first case and true in the...
Wrapper classes and generic clarifications in Java
Java : I have checked the source code for java.lang.Enum and the method T valueOf ( Class < T > enumType , String name ) beginning on line 232 ( the implementation in both java-8 and java-11 seems equal ; here is the source for Java 8 ) .What is the reason the null check for name happens after finding the enumeration b...
Why does n't java.lang.Enum : :valueOf check for the null name first ?
Java : Some devices ( e.g . webrelays ) return raw XML in response to HTTPGet requests . That is , the reply contains no valid HTTP header . For many years I have retrieved information from such devices using code like this : In openJdk 7 the following lines have been added to sun.net.www.protocol.http.HttpURLConnectio...
Retrieving XML over HTTP in Java 7
Java : I 'm using Jersey 1.12 and have an endpoint that may or may not receive malformed headers from clients that i do n't control ( for instance `` Content-Type '' : '' application/json ; bla-bla '' ) Obviously bla-bla is malformed as the spec requires parameters to have values as well i.e . bla-bla=value and thus Je...
How to have Jersey pass malformed headers
Java : I came up with two expressions to assign value from a bit operation to a variable , and noticed `` x+=y '' and `` x=x+y '' yielded different results in this case : I did some research , and found the only case `` x+=y '' and `` x=x+y '' is not equivalent is when operant types are not the same , however in this c...
Java `` x += y '' and `` x = x+y '' yields different result
Java : I sometimes have a need for classes that should only be instantiated once during the lifecycle of the application . Making them singletons is bad because then unit testing becomes problematic.But still , because there should be one and only instance of such objects during the lifecycle of my application , it wou...
How to implement a near-singleton ?
Java : I have the following static factory method that creates a list view out of an int array : In `` Effective Java '' , Joshua Bloch mentioned this as an Adapter that allows an int array to be viewed as a list of Integer instances.However , I remember that Adapter uses composition and the instance of the anonymous l...
Where is final parameter stored in anonymous class instance ?
Java : In other words , is the following line guranteed to print num lines ? This question was triggered by a discussion in the comments of https : //stackoverflow.com/a/41346586/2513200I vaguely remember a discussion that optimizations that avoid iteration might be legal , but did n't find anything conclusive during a...
Is Stream.count ( ) guranteed to visit each element ?
Java : i have following structure : Now i want to disregard the First-level-Maps and group ( and sum up ) the 3rd-Level-Maps according to the key of the 2nd-Level-Maps.To Clarify some example-Entries : Desired output : So to do this I first group my Entry-stream according to my 2nd-Level-Keys ( `` A '' , '' B '' ) and ...
Grouping of inner Maps with Java Streams
Java : I have the following types of requests.Few field examples : Mongo DB data format : Mongo DB stores user order details . Each order contains user detail [ 10 fields ] and order details [ 30 fields ] API has to give by default last 30 days of orders if no date is mentioned.My question : How can I efficiently read ...
Accessing data from mongodb
Java : I am trying to write unit tests for my Javalin.io web application . There are a few references to Mockito being used for mocking the Context objects , which is Javalins way to give the user access to the incoming web requests . I am trying to mock the .header ( String ) method of the Context class because the un...
Final Kotlin class can not be mocked because method `` should return Validator ''
Java : I have some code that takes an externally provided class name , and needs to construct an instance that implements some interface , lets call it Foo.As part of this process , I 'd like to have the following function : This obviously results in an unchecked warning , as it is genuinely unsafe - the caller may hav...
Unchecked cast when bounding the generic parameter to Class < ? >
Java : This code uses Spring 3.1 and junit4 and spring-test 3.1 . I want to turn this code using and loading junit3.8.x . This is due to a legacy build system . How can I do this ? Most of the online documentation for spring is centered around the approach below . I need to be able to 'load the spring classes ' . In th...
How can I turn this 'spring 3.1 ' oriented junit4 test with SpringJUnit4ClassRunner into a spring oriented junit3.8 based test ?
Java : Thare are two input lists as follows : My preferred output list must be as follows : What I have done so far looks like below : The output I am getting is as followsProblem is with the elements that does n't have their name in the list inputB . There order does n't have the original order in inputA . For the ori...
Sort object List by another List using Java Comparators
Java : http : //docs.oracle.com/javase/6/docs/api/java/util/Random.html # nextInt % 28int % 29 says : The algorithm is slightly tricky . It rejects values that would result in an uneven distribution ( due to the fact that 2^31 is not divisible by n ) . The probability of a value being rejected depends on n. The worst c...
Why 2^31 is not divisible by n ?
Java : I have found somewhere a pretty weird number declaration in Java.I am curious why the value of x is 5.0 <code> double x = 0xap-001 ;
Java - curious number declaration
Java : I 'm just starting out with JavaFX , and I wanted to put a WebView into a Window : It looks ever so simple , but for some reason the draw regions are being highlighted with red and green when moving the mouse around . How can I disable the flashing colors ? Update : the problem is with Groovy/Gradle interactionH...
Why is JavaFX 's WebView is flashing red and green ?
Java : I trying to get my JButton to stop its background change when clicked . I have been reading and testing answers from other questions like such but none have helped me . I am very new to Java so specific details would be helpful , here is my code and a demonstration of what is happening . Also , I am running ubun...
Stop button from being highlighted when clicked in swing
Java : I plan to execute a jar command using a jar that is included in another jar.The command will automatically obfuscate a Java jar file using code similar to : allatori.jar file is included in my main.jar file as a resource . config.xml file is also included.How can I run my command so that it executes the included...
How do I execute a jar from inside a jar ?
Java : I have some code that compiles with javac 1.8.0_92 : However , with javac 1.8.0_45 , some extra types are required ( L ) : As you can imagine , this causes issues for packages that a user builds from source . Why is this ? Is this a bug with that particular build of Java ? <code> public final class Either < L , ...
Java type inference differences between javac 1.8.0_45 and javac 1.8.0_92 ?
Java : I 'm trying to parse a week-based-year and week-of-week-based-year from a string without any separator character . E.g . `` 201812 '' ( week 12 of year 2018 ) . Like this : But this gives me : If I add a space between the fields like so : It works fine , with result : Is this another bug like this one ? Or am I ...
Parse week-based-year and week-of-week-based-year without separator character fails
Java : I want to use camunda-bpm-assert-scenario in my ScalaTests.There I have this code with receiveTask : :receive : According to answer in Is it possible to use a Java 8 style method references in Scala ? I can translate this quite easily to : But this gives me : This is the receive function : And here is the expect...
How to translate the Java double colon operator ( : : ) to Scala ?
Java : I was trying to create a few scenarios to demonstrate visibility issues while sharing variable across threads . And I noticed that in almost all the cases I tested , if inside run ( ) I added a System.out.println ( ) statement in the same block of code where I am using the shared variable , the visibility issue ...
Relationship between Threads and println ( ) statements
Java : I looking for a way to split my chunk of string every 10 words.I am working with the below code.My input will be a long string.Ex : this is an example file that can be used as a reference for this program , i want this line to be split ( newline ) by every 10 words each.Any help is appreciated . <code> private v...
How to split a string after every 10 words ?
Java : I 'm trying to make a call to Java Webstart that uses the `` -open '' run time option to send arguments to the webstart application . I have referenced the question : Passing command line arguments to javaws ( Java WebStart ) executable , but this syntax does n't seem to work for multiple arguments . It seems to...
Java Webstart `` javaws -open '' flag does n't work with multiple arguments
Java : When I add an event listener using a lambda that calls an overridable method in the constructor , I get a warning . If I use a method reference , I do n't get any warnings about overridable methods or leaking this . Should I avoid method references in the constructor or is it safe ? Here 's a simple example : <c...
Is using a reference to an overridable method in the constructor safe ?
Java : I 've been reading the OS X Java Developer Tools , in order to help make my application more `` native '' with the operating system . I found something interesting in this particular section . ( emphasis mine ) To load a resolution-independent tiff , icns , or pdf file from the Resources folder of your applicati...
How does Java load native NSImages ?
Java : With Java 8 Streams , is it possible to encapsulate and reuse intermediate stream operations in some way that wo n't break the stream pipeline ? Consider this example from the Java Tutorial on streams : Suppose I need to use the filter and mapToInt operations in different places throughout my code . I might want...
Can intermediate stream operations be encapsulated without breaking the pipeline ?
Java : I 'm confused by the DateTimeFormatter 's withZone method 's behavior when it comes to parsing . According to it 's documentation : When parsing , there are two distinct cases to consider . If a zone has been parsed directly from the text , perhaps because DateTimeFormatterBuilder.appendZoneId ( ) was used , the...
How does DateTimeFormatter 's override zone work when parsing ?
Java : I have the code above , but I ca n't work out why it produces rather thanMany thanks <code> String s = `` hi hello '' ; s = s.replaceAll ( `` \\s* '' , `` `` ) ; System.out.println ( s ) ; h i h e l l o hi hello
String.replaceAll Strange Behaviour
Java : Assume the following existing classes : now , we need to create a variant of each Axx class that overrides `` foo '' method . The basic idea was : But it seems is not posible to extend a class from one of their parametized types.The objective is to skip the need of following new code : and allow statements like ...
Java Generic class extends parametrized type
Java : If I writeAbove code works normally , but if I writeThe compiler/gradle in Android studio does n't let this one through even though it 's the same , and it says that the code after return in example 2 is unreachable.I do n't have any issues regarding this but I am eager to know why ? <code> private void check ( ...
Why does compiler build return unreachable code in some cases
Java : I have a question about this method from java.util.Collections : I understand how < ? super T > works , however , I do n't understand why the first parameter is List < ? super T > instead of List < T > . I think it 's useless in this situation.Using List < T > should work as well , should n't it ? Could you give...
Generics Collections PECS
Java : I have a question related to the following code snippet : The first call to wide_vararg fails to compile ( saying that the method is ambigous ) while the second compiles just fine . Any explanations about this behaviour ? Thanks ! <code> class VarArgsTricky { static void wide_vararg ( long ... x ) { System.out.p...
Java issue with var-args and boxing
Java : There are a few *.java files in the source tree of Scala in the scala.runtime directory.Those files seem to be very simple , e. g. DoubleRef.java looks like this : Is there any reason why those classes ca n't be defined in Scala ? <code> package scala.runtime ; public class DoubleRef implements java.io.Serializa...
What 's the purpose of these Java files in scala.runtime ?
Java : When would you ever need to use the non short circuit logical operator or ? In other words ... When would you use Instead ofIf the first conditional is true ... Then the entire statement is already true.Update : and the same question for & and & & <code> if ( x == 1 | x==2 ) if ( x == 1 || x==2 )
Logical operator OR without short circuit
Java : Using java.util.regex to extract substrings I find myself implementing the same code pattern working around calls to : Is there a functional extension or popular library ( guava / apache commons ) that avoids the ugly unnecessary and error-prone local variable , like : and also a stream of match results like : I...
Functional style java.util.regex match/group extraction
Java : At my work we recently finished the system architecture for a control application which has a maximum latency of roughly one to two seconds . It is distributed on small ARM on-chip boxes communicating via an IP LAN . We initially foresee that we would use C or C++ , since it is a classical control system languag...
~1s latency control app : is this suitable for Java ?
Java : I am wondering why the Java compiler would add a bridge method for the foo method here : The foo method is compiled to be public in the SuperClass type . Nevertheless , the SubClass method redefines the method as a bridge to the very same method . I wonder why this bridge is necessary . <code> public class Outer...
Why does the Java compiler add visibility bridge methods for public methods defined in package-private super types ?
Java : The code at the bottom of this question is a bit long but basically creates a few objects and determines their size in memory . I execute the code with the following JVM parameters ( TLAB to avoid chunk memory allocation and supposedly get accurate memory usage figures ) : I run the code on a 64 bit Hotspot JVM ...
Accurate measurement of object sizes
Java : While learning java9 StringConcatFactory class I am unable to understand why following code with MethodHandles.publicLookup ( ) throws StringConcatException exception while if MethodHandles.lookup ( ) is used everything is working fine.As per java docs of lookup : `` lookup - Represents a lookup context with the...
Exception in StringConcatFactory - Java 9
Java : The following code is working fine for m2 ( ) but is throwing a ClassCastException when I use m1 ( ) .The only difference between m1 and m2 is the number of arguments . My question is - Does varargs not work with a single argument when we use generics ? PS : This is not related to ClassCastException using Generi...
ClassCastException in varargs while using Java-8
Java : Let 's say n = 4 . With recursion I want to return : Basically I want to take number n and with by combining numbers 1,2,3 and 4 create all possible variations when the number of sum == n.This was my first idea , but it gives me Exception in thread `` main '' java.lang.StackOverflowError <code> 1 1 1 11 1 21 32 ...
Sum of numbers using recursion java