java - Passing System.out.println(); as an argument in a method -


i want pass system.out.println(); argument compiler won't allow me return void type argument. here want for.

public class array {      public static void main(string args[]) {         a(data());     }      static void a(e) {         system.out.println(e);     }      static void data() {         ...     } } 

so want a(data()); after compiled this.

a(data()) = system.out.println(data(){...}); 

eventually want shorthand system.out.println().

what doing here not passing system.out.println() argument; trying pass argument system.out.println()

try changing return type of data() string, or int, or other void, , return of type it.

also change parameter type of e in function definition of a() match return type of data().

after make these changes, calling a(data()); print out.

example:

public static void main(string args[]) {     a(data()); }  // shorthand system.out.println static void a(string e) {     system.out.println(e); }  // method returns data static string data() {     // replace whatever actual data want return     return "this data..."; } 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -