Results 1 to 3 of 3
Thread: array copy in class constructor.
- 10-27-2011, 09:56 PM #1
Member
- Join Date
- Oct 2011
- Location
- Tromsø
- Posts
- 41
- Rep Power
- 0
array copy in class constructor.
I got this code so far.
I want right to have the same values as left.Java Code:class Skosamling{ private final String merke; private final String farge; private final Integer prisPerPar; private final Integer minsteStørrelse; private final Integer[] left; private final Integer[] right; public Skosamling(String merke, String farge, Integer prisPerPar, Integer minsteStørrelse, Integer[] left, Integer[] right) { this.merke = merke; this.farge = farge; this.prisPerPar = prisPerPar; this.minsteStørrelse = minsteStørrelse; this.left[] = left[]; for(int i=0; i < left.length ; i++) { right[i] = left[i]; } this.right[] = right[]; } }
and here is the error messages I'm getting so far.
Java Code:G:\Coding\Skole\Øving 9\tabeller.java:20: error: illegal start of expression this.left[] = left[]; ^ G:\Coding\Skole\Øving 9\tabeller.java:20: error: '.class' expected this.left[] = left[]; ^ G:\Coding\Skole\Øving 9\tabeller.java:24: error: illegal start of expression this.right[] = right[]; ^ G:\Coding\Skole\Øving 9\tabeller.java:24: error: '.class' expected this.right[] = right[]; ^ 4 errors Tool completed with exit code 1
- 10-27-2011, 09:59 PM #2
Re: array copy in class constructor.
Those aren't valid variable names. Notice you're declaring them as Integer[] left, not Integer[] left[].
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-29-2011, 12:07 AM #3
Member
- Join Date
- Oct 2011
- Location
- Tromsø
- Posts
- 41
- Rep Power
- 0
Re: array copy in class constructor.
ok new try on this one.
i got two arrays that i got on the class. and when enabling it only one of those will be declared, since the last one will do one deep copy of the other one.
now, ideas on what to google for and examples that i can study to fix this ?Java Code:class shoes{ private final String brand; private final String colour; private final double price; private final int minSize; private final int[] left; private final int[] right; public shoes(String brand, String colour, double price, int minSize, int[] left, int[] right) { this.brand = brand; this.colour = colour; this.price = price; this.minSize = minSize; this.left = new int[] left; this.right = new int[] right; // thisone shall be one deep copy of the left array. } }
googleing java array kinda sucks :PLast edited by Juukamen; 10-29-2011 at 12:09 AM.
Similar Threads
-
Array copy
By lakshmibvaraprasad in forum New To JavaReplies: 16Last Post: 07-21-2011, 09:17 PM -
ISSUE: Array as class constructor will not copy elements, only reference
By Lucificate in forum New To JavaReplies: 16Last Post: 07-08-2010, 09:13 PM -
copy constructor
By shadow7 in forum New To JavaReplies: 6Last Post: 12-29-2009, 06:56 PM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks