File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

examlab,q-11(compilation error reasoning seems goes on other way)

 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

result:
according to me,i thought it was error coz the collection has not been sorted before searching in.am i right here?

but according to the simulator,it was coz st on line 1 has not been casted to list.
if line1 is modified to as per simulator says below,cabove code should compile but it doesn't.
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats because linkedlist is a Collection not Collections.
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha Daga wrote:Thats because linkedlist is a Collection not Collections.

NO,
list is an in interface i.e.Collection.
linkedlist is a class(Collections) that implements list.
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arjun Srivastava wrote:
list is an in interface i.e.Collection.
linkedlist is a class(Collections) that implements list.


Yes, but I dont see Linkedlist extending Collections class anywhere.
 
Piotr Nowicki
Ranch Hand
Posts: 610
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Arjun!

Did you check what is the compiler error in the first place?
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, i am so dumb,above code has been modified it was collection ,not collections on line2
but error persists,cannot find symbol on line1.
 
Neha Daga
Ranch Hand
Posts: 504
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try casting 'st' to List<String> it will work fine. And there is no compiler error its compiler warning because of mixing generic and non generic collections.
 
Piotr Nowicki
Ranch Hand
Posts: 610
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, try to compile the code from the first post with the change you already posted (casting to List).

On my computer it works just fine...
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha Daga wrote:try casting 'st' to List<String> it will work fine. And there is no compiler error its compiler warning because of mixing generic and non generic collections.

yea ,this casting of st to(List<String>) works fine instead of (List)(as given in simulator)

Pedro Kowalski wrote:Please, try to compile the code from the first post with the change you already posted (casting to List).
On my computer it works just fine...

no pedro, casting st to (List) only didn't work in my system.
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to me,i thought it was error coz the collection has not been sorted before searching in.am i right here?
but it was not the case why so,how we can able to search without doing sorting?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arjun Srivastava wrote:according to me,i thought it was error coz the collection has not been sorted before searching in.am i right here?
but it was not the case why so,how we can able to search without doing sorting?

Hey, Arjun! => UseRealWords Does the compiler have the sense of sorting? It checks the syntax of your code, that's only!
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:
Does the compiler have the sense of sorting? It checks the syntax of your code, that's only!

got it.
if the array or collection has not been sorted before searching,then output will not be predictable.
i thought it was a compiler error,thank god i got to know this thing before exam.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arjun Srivastava wrote:
Abimaran Kugathasan wrote:
Does the compiler have the sense of sorting? It checks the syntax of your code, that's only!

got it.
if the array or collection has not been sorted before searching,then output will not be predictable.

Exactly!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic