• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats because linkedlist is a Collection not Collections.
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic