Commit 817147f8 by Patryk Czarnik

poprawki w gotowych

parent b39dd039
...@@ -35,8 +35,7 @@ public class Polimorfizm1 { ...@@ -35,8 +35,7 @@ public class Polimorfizm1 {
} }
/** Zamienia pierwszy element z ostatnim i zwraca ich średnią */ /** Zamienia pierwszy element z ostatnim i zwraca ich średnią */
static <T extends Number> double sredniaZZamiana(List<T> lista) { static <T extends Number> double sredniaZZamiana(List<T> lista) {
T pierwszy = lista.get(0); T pierwszy = lista.get(0);
T ostatni = lista.get(lista.size()-1); T ostatni = lista.get(lista.size()-1);
......
...@@ -4,7 +4,7 @@ import java.util.Objects; ...@@ -4,7 +4,7 @@ import java.util.Objects;
// Za pomocą ograniczeń "extends" oraz "super" możemy wymusić, że parametr typowy // Za pomocą ograniczeń "extends" oraz "super" możemy wymusić, że parametr typowy
// spełnia pewne warunki. // spełnia pewne warunki.
// W tym przypadku T extends Number oznacza, że T to może byc Number, Integer, Double itd., ale nie String, Object czy inne typy // W tym przypadku T extends Number oznacza, że T to może byc Number, Integer, Double, BigDecimal itd., ale nie String, Object czy inne typy
public class ParaLiczb<T extends Number> { public class ParaLiczb<T extends Number> {
private T lewy; private T lewy;
private T prawy; private T prawy;
......
...@@ -6,6 +6,9 @@ public class Test2 { ...@@ -6,6 +6,9 @@ public class Test2 {
public static void main(String[] args) { public static void main(String[] args) {
ParaLiczb<Integer> para1 = new ParaLiczb<>(new Integer(13), new Integer(3000)); ParaLiczb<Integer> para1 = new ParaLiczb<>(new Integer(13), new Integer(3000));
ParaLiczb<Integer> para1a = new ParaLiczb<>(13, 3000);
ParaLiczb<Integer> para1b = new ParaLiczb<>(Integer.valueOf(13), Integer.valueOf(3000));
System.out.println(para1); System.out.println(para1);
Number lewy = para1.getLewy(); Number lewy = para1.getLewy();
...@@ -13,7 +16,7 @@ public class Test2 { ...@@ -13,7 +16,7 @@ public class Test2 {
//NK para1.setLewy(new Double(3.14)); //NK para1.setLewy(new Double(3.14));
para1.setLewy(new Integer(44)); para1.setLewy(44);
// Wiedząc, że jest to para liczb, mogę korzystać z operacji matematycznych // Wiedząc, że jest to para liczb, mogę korzystać z operacji matematycznych
double avg = para1.getSrednia(); double avg = para1.getSrednia();
......
...@@ -27,7 +27,7 @@ public class PrzykladRefleksji { ...@@ -27,7 +27,7 @@ public class PrzykladRefleksji {
} }
try { try {
Class<?> klasa3 = Class.forName("pcz.p29_refleksja.klasy.Osoba"); Class<?> klasa3 = Class.forName("gotowe.p29_refleksja.klasy.Osoba");
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment