• Post Reply Bookmark Topic Watch Topic
  • New Topic

stuck with Arrays syntax in an ArrayList  RSS feed

 
Giovanni Montano
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI dev,
I am following a tutorial, is quite complex but quite logical, is about to write and read a file using an Array that refers to a third class(person) that has a nice contructor.
despite some initial challenge I understood the mechanism but under ReadProjects Class there is a line of code eclipse does not allow me to compile
ArrayList<Person> peopleList=(ArrayList<Person>)os.readObject()(Arrays.asList(people));
I have the error message in eclipse
with The operator * is undefined for the argument type(s) ArrayList<Person>, List<Person>
or without putting the ;
i have the message error
The left-hand side of an assignment must be a variable
thanks
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The operator * is undefined for the argument type(s) ArrayList<Person>, List<Person>
Syntax error on token ")", * expected after this token

at ReadProjects.main(ReadProjects.java:17)









 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First, please read this...

http://www.coderanch.com/how-to/java/FixAllCompilerErrorsBeforeRunningTheApplication


But to answer your question....

Giovanni Montano wrote:
I understood the mechanism but under ReadProjects Class there is a line of code eclipse does not allow me to compile
ArrayList<Person> peopleList=(ArrayList<Person>)os.readObject()(Arrays.asList(people));


It quite clear why that line doesn't compile. It isn't valid Java. It's a syntax error. My question is, why do you think it is valid? and if so, what is that line supposed to do?

Henry
 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure your brackets are where you want them to be after readObject.

Edit: Too slow again.
 
Giovanni Montano
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony and Henry thank you really!

I did one small typo I put the original code again here, truly apologize.
the row:
ArrayList<Person> peopleList=new ArrayList<Person>(Arrays.asList(people));
goes inside writeObject not readObject
, now is compiling inside writeObject, (but does not compile read Object( that has another main inside)
regarding your questions about synthax is compiling despite is quite odd as synthax( or at least I never met it

for more here it is the link where I took
http://www.caveofprogramming.com/frontpage/youtube/java-video/serializing-multiple/








 
sai rama krishna
Ranch Hand
Posts: 536
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like there is compilation error. And also corrected as below right
ArrayList<Person> peopleList = new ArrayList<Person>(Arrays.asList(people));
So you are creating array and then adding it to ArrayList before writing it. Is there any other place in the code you are facing issues?
 
Giovanni Montano
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai rama krishna wrote:Looks like there is compilation error. And also corrected as below right
ArrayList<Person> peopleList = new ArrayList<Person>(Arrays.asList(people));
So you are creating array and then adding it to ArrayList before writing it. Is there any other place in the code you are facing issues?

ues, so also the try at line18 give me error but I guess it is because is a new java 7 construct so my compiler is not set. In any case it is another main so it is independent, my focus is on this syntax ArrayList above mentioned also by you, that now is not giving me error, it is a new construct I have never seen, I could not figure out you can put parenthesis with the instruction Arrays after new ArrayList<Person>, but now it looks as it is possible as the compiler recognize it as exact, thanks all, I guess case solved
 
Giovanni Montano
Ranch Hand
Posts: 434
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, sorry;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!