fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. String[] sources = {"test1", "test2"};
  14. List<Stream> elem = Media.getList(sources);
  15. }
  16. }
  17.  
  18. abstract class Media
  19. {
  20. String url;
  21.  
  22. protected Media(String source) {
  23. url = source;
  24. }
  25.  
  26. public static <T extends Media> List<T> getList(String[] sources) {
  27. List<T> newList = new ArrayList<T>();
  28. for (String source: sources) {
  29. newList.add(T.getInstance(source));
  30. }
  31. return newList;
  32. }
  33.  
  34. public static <M extends Media> M getInstance(String source) {
  35. return null;
  36. }
  37. }
  38.  
  39. interface Instance {
  40. abstract public static Media getInstance(String source);
  41. abstract public static List<Media> getList(String[] sources);
  42. }
  43.  
  44. class Stream extends Media implements Instance
  45. {
  46. public Stream(String source) {
  47. super(source);
  48. }
  49.  
  50. public static Stream getInstance(String source) {
  51. return new Stream(source);
  52. }
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:40: error: modifier static not allowed here
	abstract public static Media getInstance(String source);
	                             ^
Main.java:41: error: modifier static not allowed here
	abstract public static List<Media> getList(String[] sources); 
	                                   ^
Main.java:29: error: no suitable method found for add(Media)
			newList.add(T.getInstance(source));
			       ^
    method List.add(int,T) is not applicable
      (actual and formal argument lists differ in length)
    method List.add(T) is not applicable
      (actual argument Media cannot be converted to T by method invocation conversion)
  where T is a type-variable:
    T extends Media declared in method <T>getList(String[])
Main.java:44: error: Stream is not abstract and does not override abstract method getList(String[]) in Instance
class Stream extends Media implements Instance
^
Main.java:50: error: getInstance(String) in Stream cannot implement getInstance(String) in Instance
	public static Stream getInstance(String source) {
	                     ^
  overriding method is static
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
stdout
Standard output is empty