Gemeinsames Lernen
This commit is contained in:
112
src/org/eidecker/oca8lernen/general/Lernkleinigkeiten.java
Normal file
112
src/org/eidecker/oca8lernen/general/Lernkleinigkeiten.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package org.eidecker.oca8lernen.general;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author seidecke.
|
||||
*/
|
||||
public class Lernkleinigkeiten {
|
||||
|
||||
@Test
|
||||
public void optionalMapping() {
|
||||
Optional<BigDecimal> maybeBigDecimal = Optional.ofNullable(BigDecimal.ONE);
|
||||
Optional<Kosten> maybeKosten;// = Optional.of(new Kosten());
|
||||
|
||||
maybeKosten = maybeBigDecimal.map(Kosten::new);
|
||||
maybeBigDecimal = maybeKosten.map(Kosten::getValue);
|
||||
maybeBigDecimal = Optional.of(maybeKosten.get().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolymorphieUndFelder() throws Exception {
|
||||
Ober2 ober = new Unter2();
|
||||
System.out.println(ober.s);
|
||||
System.out.println(ober.s2);
|
||||
|
||||
Unter2 unter = new Unter2();
|
||||
System.out.println(unter.s);
|
||||
System.out.println(unter.s2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnSyntaxTest() {
|
||||
assertEquals(1, returnSyntax(1));
|
||||
throwNull();
|
||||
}
|
||||
|
||||
private int returnSyntax(int i) {
|
||||
;;;;;;;;;;;;
|
||||
if (i == 1) {
|
||||
return(1);
|
||||
} else {
|
||||
return (i + 1);
|
||||
}
|
||||
};
|
||||
|
||||
private int throwNull() {
|
||||
throw null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Kosten {
|
||||
public Kosten(BigDecimal value) {
|
||||
}
|
||||
|
||||
BigDecimal getValue() {
|
||||
if (false) {
|
||||
}
|
||||
return BigDecimal.ONE;
|
||||
}
|
||||
|
||||
BigDecimal getValueUnsafe() throws IOException {
|
||||
if (false) {
|
||||
}
|
||||
return BigDecimal.ONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Ober2 {
|
||||
|
||||
public String s = "Ober2";
|
||||
public String s2 = "Noch ein Feld aus Ober2";
|
||||
|
||||
public Ober2() throws IOException {
|
||||
}
|
||||
|
||||
public List getS() throws IOException {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
|
||||
class Unter2 extends Ober2 {
|
||||
|
||||
public String s = "Unter2";
|
||||
|
||||
public Unter2() throws Exception{
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList getS() throws AccessDeniedException {
|
||||
int i = 1;
|
||||
do {
|
||||
|
||||
} while (i == 1);
|
||||
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ public class PrimitiveUndWrapperTest {
|
||||
char c = (char) 1L;
|
||||
|
||||
short sh = Short.MAX_VALUE;
|
||||
char s = sh;
|
||||
// char s = sh;
|
||||
|
||||
"Hallo".concat()
|
||||
"Hallo".concat(" Welt");
|
||||
|
||||
System.out.println(s);
|
||||
// System.out.println(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,9 +10,14 @@ public class SwitchSyntax {
|
||||
Integer i = 1;
|
||||
|
||||
switch(getSwitchBEdingung()) {
|
||||
case 1:
|
||||
System.out.println("1");
|
||||
case 1: {
|
||||
int j;
|
||||
System.out.println("1");
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
default:
|
||||
int j;
|
||||
System.out.println("default");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user