Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Static imports clarification

Posts: 17
Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I was going through the Sybex book for the OCAJP preparation and came across below code. It says the code does not compile because - ""We imported the asList method. However, we did not import the Arrays class anywhere. This makes it okay to write asList(“one”); but not Arrays.asList(“one”);""  But when I tested it I was able to compile it. Is there something that am missing?

Ranch Hand
Posts: 207
Oracle MySQL Database Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea here you get CT Error because you have imported the static member "asList" of Arrays class ok. But in your code you are using "Arrays.asList" so here you are using "Arrays.asList", but you haven't imported the Arrays class of util package, that's why error.
a wee bit from the empire
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic