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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -