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

    Jun 8, 2009 · 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 need to use guava for this particular reason in Java 8. The method name is a bit different though. Builder pattern

  2. java - Method accepting two different types as parameter - Stack …

    May 28, 2012 · I am writing a method that should accept as its parameter an object of one of two types which do not share a parent type other than Object. For example, the types are Dreams and Garlic. You can do both dreams.crush() and garlic.crush(). I want to have a method utterlyDestroy(parameter), that would accept as its parameter both Dreams and Garlic.

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

    Dec 4, 2009 · Java also provides a nice way of calling async methods. in java.util.concurrent we have ExecutorService that helps in doing the same. Initialize your object like this - private ExecutorService asyncExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); and then call …

  4. Calling Non-Static Method In Static Method In Java

    Jan 11, 2010 · It is not possible to call non-static method within static method. The logic behind it is we do not create an object to instantiate static method, but we must create an object to instantiate non-static method. So non-static method will not get object for its instantiation inside static method, thus making it incapable for being instantiated.

  5. Cannot make a static reference to the non-static method

    Make the variable a member variable (field) of the Activity or other subclass of Context by removing the static modifier and placing it within the class body; Keep it static and delay the initialization to a later point (e.g. in the onCreate method); Make it …

  6. Return different type of data from a method in java?

    No. Java methods can only return one result (void, a primitive, or an object), and creating a struct-type class like this is exactly how you do it. As a note, it is frequently possible to make classes like your ReturningValues immutable like this:

  7. 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 @VisibleForTesting annotation, but it's only for documentation purposes.

  8. java - Make a variable accessible by all methods - Stack Overflow

    I'm a bit new to java and i recently learned about methods(so cool!). I want to know if its possible to declare a variable in my main method and use it in my other methods. What i am trying to do is

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

    Then, to call on the method, type pause(ms) but replace ms with the number of milliseconds to pause. That way, you don't have to insert the entire try-catch statement whenever you want to pause. That way, you don't have to insert the entire try-catch statement whenever you want to …

  10. Java: How To Call Non Static Method From Main Method?

    Since you want to call a non-static method from main, you just need to create an object of that class consisting non-static method and then you will be able to call the method using objectname.methodname(); But if you write the method as static then you won't need to create object and you will be able to call the method using methodname(); from ...