i get the error :
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Float
at de.codegym.task.task14.task1418.Solution.processCastObjects(Solution.java:43)package de.codegym.task.task14.task1418;
import java.util.LinkedList;
import java.util.List;
/*
Vier Fehler korrigieren
*/
public class Solution {
public static void main(String[] args) {
List<Number> list = new LinkedList<>();
initList(list);
printListValues(list);
processCastObjects(list);
}
public static void initList(List<Number> list){//dhahrli lezem na3ml copy !
list.add(new Double(1000f));
list.add(new Double("123e-445632"));
list.add(new Float(-90 / -3));
list.remove(new Double("123e-445632"));
}
public static void printListValues (List<Number> list){//lezem mzid void lehne
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
//sala7t tletha a8lat !
}
public static void processCastObjects(List<Number> list){//7ata lehne void
for (Number object : list) {
// 2 Fehler korrigieren
if (object instanceof Float) {
Double a = (Double) object;
System.out.println("Ist float definiert? " + !(a.isNaN()));
} else if (object instanceof Double) {
Float a = (Float) object;
System.out.println("Ist double unendlich?" + a.isInfinite());
}
}
}
}