generic argument java
static void fromArrayToCollection(Object[] a, Collection<?> c) {
for (Object o : a) {
c.add(o); // compile-time error
}
}
generic argument java
static void fromArrayToCollection(Object[] a, Collection<?> c) {
for (Object o : a) {
c.add(o); // compile-time error
}
}
generic argument java
static void fromArrayToCollection(Object[] a, Collection<?> c) {
for (Object o : a) {
c.add(o); // compile-time error
}
}
generics in java
import java.util.Scanner;
import reader.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
String filePath = scanner.nextLine().trim();
System.out.println("The file path is " + filePath);
String type = filePath.substring(filePath.lastIndexOf('.') + 1).replaceAll("\\W", "");
System.out.println("The reader type is " + type);
AbstractReaderService reader = getReaderService(type);
// reader.read(filePath);
// reader.printContent();
}
private static AbstractReaderService getReaderService (String type) throws Exceptions.TypeNotFoundException {
switch (type) {
case "txt": return new TxtReaderService();
case "json": return new JsonReaderService();
default: throw new Exceptions().new TypeNotFoundException("There is no \"" + type + "\" type of reader.");
}
}
}
generics in java
import java.util.Scanner;
import reader.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
String filePath = scanner.nextLine().trim();
System.out.println("The file path is " + filePath);
String type = filePath.substring(filePath.lastIndexOf('.') + 1).replaceAll("\\W", "");
System.out.println("The reader type is " + type);
AbstractReaderService reader = getReaderService(type);
// reader.read(filePath);
// reader.printContent();
}
private static AbstractReaderService getReaderService (String type) throws Exceptions.TypeNotFoundException {
switch (type) {
case "txt": return new TxtReaderService();
case "json": return new JsonReaderService();
default: throw new Exceptions().new TypeNotFoundException("There is no \"" + type + "\" type of reader.");
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us