• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java 7 "Diamond in Generic"

 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

FileFilter.java:13: error: cannot infer type arguments for Filter<T>;
DirectoryStream.Filter<Path> fileFilter=new DirectoryStream.Filter<>(){
^

1 error

Normally it works like List<String> list=new ArrayList<>();

But why it isn't working above ?
 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems Diamond doesn't work with inner class.
 
Tony Docherty
Bartender
Posts: 2971
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems Diamond doesn't work with inner class.

It does work with inner classes but not with anonymous inner classes.

According to the JLS section 15.9:
"It is a compile-time error if a class instance creation expression declares an anonymous class using the "<>" form for the class's type arguments."
 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic