| Author |
Arrays.copyOf() error
|
Sihle Manqele
Greenhorn
Joined: Sep 28, 2006
Posts: 5
|
|
Hi ranchers, i've come across a very interesting compile-time error which is completely throwing me off. I'm testing how Arrays class works and have the following lines of code: Arrays.fill(intArr,16); int[] intTest = Arrays.copyOf(new int[4], 8); I get the compile error: StringArrayObjectTest.java:17: cannot find symbol symbol : method copyOf(int[],int) location: class java.util.Arrays int[] intTest = Arrays.copyOf(new int[4], 8); ^ Am I not using copyOf() the way it's supposed to be used? This is not compiling in jdk1.5.0_01 and jdk1.5.0_05. Thanks Sihle
|
 |
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
|
|
Hi Sihle, the code does not compile because there is no such a Method "copyOf" in java.util.Arrays. Perhaps try the clone method of the array object itself, eg. Yours, Bu.
|
 |
Sihle Manqele
Greenhorn
Joined: Sep 28, 2006
Posts: 5
|
|
|
Hi Burkhard, Thanks for the reply. The reason I asked this question is because copyOf is described in great detail on the official Arrays doc. The question then becomes, should I not take everything in the docs as fact? It feels really cruel from Sun to do this to people who read and depend on these docs to implement solutions!
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
Sihle, you are looking at the documentation of JDK 1.6, but you are using version 1.5. The copyOf(...) methods in class Arrays are new in 1.6, and the documentation mentions this ("Since: 1.6"). Use the API documentation of version 1.5.0 if that's the version you're using.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
In each new version of Java, new classes and methods are added to the APIs. Older versions of Java won't know about these classes and methods, of course. Arrays.copyOf() is a new method in Java 6 ("Mustang"), which is still in beta -- it hasn't been formally released. Java 5 is the current version, and that's probably what you're using on your desktop. You must have been browsing the beta documentation on Sun's web site. So either use the Java 5 documentation, or download the Java 6 beta software. [ October 20, 2006: Message edited by: Ernest Friedman-Hill ]
|
[Jess in Action][AskingGoodQuestions]
|
 |
Sihle Manqele
Greenhorn
Joined: Sep 28, 2006
Posts: 5
|
|
Hi guys, Yep, that explains it! It clarifies my whole confusion. Thanks a lot for the feedback...
|
 |
Devan Brahma
Ranch Hand
Joined: Jul 07, 2009
Posts: 46
|
|
thanks dudes,,,
that solves my problem too
|
->R§H<-
|
 |
 |
|
|
subject: Arrays.copyOf() error
|
|
|