About 368,000 results
Open links in new tab
  1. How do I use optional parameters in Java? - Stack Overflow

    Optional makes a method contract explicit for a caller, however, one may find such signature too verbose. Update: Java 8 includes the class java.util.Optional out-of-the-box, so there is no …

  2. wait - How do I make a delay in Java? - Stack Overflow

    613 I am trying to do something in Java and I need something to wait / delay for an amount of seconds in a while loop.

  3. How to asynchronously call a method in Java - Stack Overflow

    System.out.println("Method is finished!"); Internally I'm using a class that implements Runnable and do some Reflection work to get the correct method object and invoking it. I want some …

  4. java - When to use static methods - Stack Overflow

    Mar 6, 2017 · I am wondering when to use static methods? Say if I have a class with a few getters and setters, a method or two, and I want those methods only to be invokable on an instance …

  5. How do I make the method return type generic? - Stack Overflow

    May 24, 2016 · Afaik, Java and most typed languages don't overload methods or functions based on return type. For instance public int getValue(String name){} is indistinguishable from public …

  6. java - annotation to make a private method public only for test …

    The common way is to make the private method protected or package-private and to put the unit test for this method in the same package as the class under test. Guava has a …

  7. How to declare or mark a Java method as deprecated?

    Jan 27, 2012 · Using the annotation causes the Java compiler to generate warnings when the deprecated class, method, or field is used. The compiler suppresses deprecation warnings if a …

  8. How do I define a method which takes a lambda as a parameter in …

    Nov 28, 2012 · In Java 8, methods can be created as Lambda expressions and can be passed by reference (with a little work under the hood). There are plenty of examples online with lambdas …

  9. How to call a method with a separate thread in Java?

    Aug 15, 2010 · In your "main" thread, create a new Thread class, passing the constructor an instance of your Runnable, then call start() on it. start tells the JVM to do the magic to create a …

  10. java - How do I test a class that has private methods, fields or …

    Aug 29, 2008 · How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to …