Skip to content

Instantly share code, notes, and snippets.

@nea89o
Created October 23, 2018 12:47
Show Gist options
  • Save nea89o/6361aca8311158d1bcc775c8e3628b94 to your computer and use it in GitHub Desktop.
Save nea89o/6361aca8311158d1bcc775c8e3628b94 to your computer and use it in GitHub Desktop.
Komposition created by romangraef - https://repl.it/@romangraef/Komposition
class Futter {
String name;
float mass;
public Futter(String name) {
this.name = name;
this.mass = 100f;
}
public String toString(){
return "Futter: "+name + ", "+mass+"g.";
}
}
import java.util.Optional;
class Futternapf {
Optional<Futter> futter;
public Futternapf() {
futter = Optional.empty();
}
public void refillFutter(String name) {
futter = Optional.of(new Futter(name));
}
public String toString() {
return "Futternapf. Futter: "+futter;
}
}
class Main {
public static void main(String[] args) {
Futternapf f = new Futternapf();
System.out.println(f);
f.refillFutter("Premium Futter");
System.out.println(f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment