Added example of Method Reference for a super method of a particular object and fixed for instance method of an arbitrary object of a particular type.
This commit is contained in:
@@ -44,6 +44,18 @@ public class Computer {
|
||||
this.healty = healty;
|
||||
}
|
||||
|
||||
public void turnOnPc() {
|
||||
System.out.println("Computer turned on");
|
||||
}
|
||||
|
||||
public void turnOffPc() {
|
||||
System.out.println("Computer turned off");
|
||||
}
|
||||
|
||||
public Double calculateValue(Double initialValue) {
|
||||
return initialValue/1.50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Computer{" + "age=" + age + ", color='" + color + '\'' + ", healty=" + healty + '}';
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.doublecolon;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public class MacbookPro extends Computer{
|
||||
|
||||
public MacbookPro(int age, String color) {
|
||||
super(age, color);
|
||||
}
|
||||
|
||||
public MacbookPro(Integer age, String color, Integer healty) {
|
||||
super(age, color, healty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnPc() {
|
||||
System.out.println("MacbookPro turned on");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOffPc() {
|
||||
System.out.println("MacbookPro turned off");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double calculateValue(Double initialValue){
|
||||
|
||||
Function<Double,Double> function = super::calculateValue;
|
||||
final Double pcValue = function.apply(initialValue);
|
||||
System.out.println("First value is:" +pcValue);
|
||||
return pcValue + (initialValue/10) ;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user