Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
public class KomplexeDatenstruktur{
private static float eineConstante = 4.6f;
private static class Data{
/*
man kann sie auch sowohl öffentlich als auch als äußere Klasse machen,
aber wenn man die Klasse 'Data' gar nicht an andere Stelle braucht,
weil sie evtl. nur als Hilfklasse für diese 'KomplexeDatenstruktur' dient,
ist das eigentlich eine gute Lösung.
Es ist halt nur eine Schönheitsfrage und geht auch immer als äußere oder öffentliche innere Klasse.
Eine Klasse innerhalb einer anderen zu machen, kann auch den Vorteil haben,
dass sie die privaten Varibalen der um schließenden Klasse nutzen kann.
Eine Statische inner Class kann dabei die statischen Varibablen nutzen und eine nicht statische sogar
die Instanz Variblen (Beispiel zum Schluss)
*/
public void setFoo(int foo){
this.foo = foo * eineConstante;
}
public byte[] getBytes(){
return ...
}
}
...
// ganz viele gemeine Sachen
...
public InputStream asByteStream(){
return new InputStream(){ // halt die anonyme Klasse
private final Iterator<Data> i = datas.iterator();
private InputStream aktStream = null;
public int read() throws IOException {
if(aktStream == null){
if(!i.hasNext()) return -1;
aktStream = new ByteInputStream(i.next().getBytes());
}
int r = aktStream.read();
while(r == -1 && i.hasNext()){
aktStream = new ByteInputStream(i.next().getBytes());
r = aktStream.read();
}
return r;
}
};
}
}
public class Fabrik{
public static void main(String[] args){
Fabrik f = new Fabrik();
f.setAktYear(2002);
Fabrik.Car c1 = f.new Car();
System.out.println(c1.getQualtität());
f.setAktYear(2006);
Fabrik.Car c2 = f.new Car();
System.out.println(c2.getQualtität());
}
private Foo w;
private int aktYear;
public void setFoo(Foo val){
w = val;
}
public void setAktYear(int y){
this.aktYear = y;
}
public class Car{
private final int baujahr;
public Car(){
this.baujar = aktYear;
}
public float getQualtität(){
return foo * Math.PI * baujahr / 0815;
}
}
}