Error in Array object creation | Selenium Forum
M
Posted on 16/10/2016
While i am creating an array object and trying to give integer value to it iam getting error

error:Type mismatch: cannot convert from int to Object

Object str[]=new Object[5];

str[0]="prathap";
str[1]=1234;

M
Replied on 17/10/2016

[b:1drafz2v][u:1drafz2v]Reason for this issue:[/u:1drafz2v][/b:1drafz2v]You declared object array as "String" and trying to pass int value

You are encountering this issue, as you are passing integer value(1234) in Str[1]

change this value as
Str[1]="1234"

Anyways, wait for reply from Ashish team


M
Replied on 17/10/2016

you're right SK.


M
Replied on 29/10/2016

Sir thanks for the reply.

Sir if we want to give every item in string, then we can use directly string array, then what will be the use of an "Object" ?

I believe an array object should store and type of data type items.

As u said we can use the below

String arr[]=new String[5];

arr[0]="123";



Then what is the use of below syntax, when can we use this

Object str[]=new Object[4];



Please clarify


M
Replied on 31/10/2016

By using below syntax, you can declare any variable (string or int)

[b:ckcokkwb]Reason[/b:ckcokkwb]:[b:ckcokkwb]You can use Object for storing any type of value for e.g. int, float, String[/b:ckcokkwb]



Object str[]=new Object[4];

str[0]="Test"
str[1]=1234;
str[2]=2345;
str[3]="String";

Anyways, wait for a better solution from Ashish team.


M
Replied on 23/11/2016

Sir any upadtes on this


M
Replied on 23/11/2016

[quote="veerus.scsvmv@gmail.com":5j85qano]Then what is the use of below syntax, when can we use this

Object str[]=new Object[4];[/quote:5j85qano]

An object is an instance of a class in Java. we can declare any datatype by using above syntax.

str[0]="Username"
str[1]=12;
str[2]=234.56
str[3]="user@gmail.com"


M
Replied on 23/11/2016

[quote="veerus.scsvmv@gmail.com":2k85muyi]Sir any upadtes on this[/quote:2k85muyi]

this question has been already answered.