92. LVTI and the method return and argument types

As a rule of thumb, LVTI cannot be used as a return method type or as an argument method type; instead, variables of the var type can be passed as method arguments or store a return method. Let's iterate these statements via several examples:

  • LVTI cannot be used as the method return type—the following code doesn't compile:
// Does not compile
public var fetchReport(Player player, Date timestamp) {

return new Report();
}
  • LVTI cannot be used as a method argument type—the following code doesn't compile:
public Report fetchReport(var player, var timestamp) {

return new Report();
}
  • Variables of the var type can be passed as method arguments or store a return method—the following code compiles successfully and it works:
public Report checkPlayer() {

var player = new Player();
var timestamp = new Date();
var report = fetchReport(player, timestamp);

return report;
}

public Report fetchReport(Player player, Date timestamp) {

return new Report();
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset