generics - Java: Casting a List<?> without warning -
assume have following example code.
first class:
public class template<t> {      private final t val;      public template(t val) {         this.val = val;     }      public t getval() {         return val;     } } second class:
import java.util.arraylist; import java.util.list;  public class app {      public static void main(string[] args) {          list<?> templates = new arraylist<template<?>>();          // how can cast without warning?         list<template<?>> castedtemplates = (list<template<?>>)templates;          // further code...     } } so, question is: how can cast without warning , without @suppresswarnings("unchecked")?
why if can define list<template<?>> templates = new arraylist<template<?>>();?
Comments
Post a Comment