Last active
June 24, 2021 16:11
-
-
Save erictroebs/4f9f3c611cddb903b08a658605f47ec6 to your computer and use it in GitHub Desktop.
ClassCastException when converting generic lists to arrays in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.LinkedList; | |
public class TestMenge { | |
LinkedList<String> StringList = new LinkedList<>(); | |
public String[] getElements() { | |
return (String[]) StringList.toArray(); | |
} | |
public static void main(String[] args) { | |
System.out.println(Runtime.version().toString()); | |
System.out.flush(); | |
TestMenge test = new TestMenge(); | |
String[] StringArray = test.getElements(); | |
System.out.println(Arrays.toString(StringArray)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment