Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Array of Type Object

Thread view: 
John A. Bailo - 05 Jun 2007 23:48 GMT
If I do this:

    Object arguments = new Object[8];

And then

    arguments[0]= "John";

The compile throws an error:

    array required, but java.lang.Object found

Why?
Owen Jacobson - 05 Jun 2007 23:53 GMT
> If I do this:
>
[quoted text clipped - 9 lines]
>
> Why?

Because the static type (the type you declared) of the arguments
variable is not an array.  Change the declaration: Object[] arguments
= new Object[8].

Owen
John Bailo - 06 Jun 2007 00:18 GMT
>> If I do this:
>>
[quoted text clipped - 15 lines]
>
> Owen

DUH!

Thanks>>>>
Stefan Ram - 06 Jun 2007 00:15 GMT
>Object arguments = new Object[8];
>arguments[0]= "John";

public class Main
{ public static void main( final java.lang.String[] args )  
 { final java.lang.Object array = new java.lang.Object[ 8 ];
   java.lang.reflect.Array.set( array, 0, "Alpha" );
   java.lang.System.out.print
   ( java.util.Arrays.toString(( java.lang.Object[] )array )); }}

[Alpha, null, null, null, null, null, null, null]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.