About 73,400 results
Open links in new tab
  1. What does void do in java? - Stack Overflow

    The reason the code will not work without void is because the System.out.println(String string) method returns nothing and just prints the supplied arguments to the standard out terminal, which is the computer monitor in most cases. When a method returns "nothing" you have to specify that by putting the void keyword in its signature.

  2. How to break out or exit a method in Java? - Stack Overflow

    Jun 3, 2016 · From the Java Tutorial that I linked to above: Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this: return;

  3. What does the return keyword do in a void method in Java?

    Oct 9, 2014 · You can have return in a void method, you just can't return any value (as in return 5;), that's why they call it a void method. Some people always explicitly end void methods with a return statement, but it's not mandatory. It can be used to leave a function early, though:

  4. java - When does a 'void' method affect the parameter, and when …

    Apr 7, 2013 · public static void editnumbersNotArray(int a){ a = 9; **//<--while this one only changes 'a' instead of 'y'?** } } So my question is basically typed in there as comments. Why does the array that is passed into the method change the values of the original array (x[]) when the int that is passed into the other method doesnt change?

  5. java - How to specify function types for void (not Void) methods in ...

    Jan 14, 2013 · The println method is appropriate because it receives a value and has a return type void, just like the accept method in Consumer. So, in your code, you need to change your method signature to somewhat like: public static void myForEach(List<Integer> list, Consumer<Integer> myBlock) { list.forEach(myBlock); }

  6. java - How to mock void methods with Mockito - Stack Overflow

    How to mock void methods with mockito - there are two options: doAnswer - If we want our mocked void method to do something (mock the behavior despite being void). doThrow - Then there is Mockito.doThrow() if you want to throw an exception from the mocked void method.

  7. java - What is the purpose of void? - Stack Overflow

    Mar 25, 2013 · Void class is an uninstantiable class that hold a reference to the Class object representing the primitive Java type void. and The Main method is the method in which execution to any java program begins.

  8. Java 8 lambda Void argument - Stack Overflow

    Apr 29, 2015 · Let's say I have the following functional interface in Java 8: interface Action&lt;T, U&gt; { U execute(T t); } And for some cases I need an action without arguments or return type. So I write

  9. What is the difference between java.lang.Void and void?

    java.lang.Void is analogous to java.lang.Integer. Integer is a way of boxing values of the primitive type int. Void is a way of boxing values of the primitive type void. "But wait, void doesn't have any possible values!" Right! That's what makes java.lang.Void "uninstantiable".

  10. java - Mockito test a void method throws an exception - Stack …

    Mar 1, 2013 · I have a method with a void return type. It can also throw a number of exceptions so I'd like to test those exceptions being thrown. All attempts have failed with the same reason: The method when(T) in the type Stubber is not applicable for the arguments (void) Any ideas how I can get the method to throw a specified exception?

Refresh