Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Conversion of 'Array object'!

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

public void printArray(long a[])
{
for(int i=0;i<a.length;i++)>
{
System.out.println(a[i]);
}
}

If this method is called like this
int b[]={1,2,3,4};
printArray(b);

it says no method matching 'printArray[int)' found error I am getting.
Is it because of Once array is constructed,it can not be modified(immutable)!.
I am not clear,please can some body help me.
Thanks in advance.
Nirmala
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Primitive arrays are not automatically "widened" like object reference arrays.
Khalid
 
Nirmala
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Khalid,
Can you give me an example,I really appreciate it.
Thanks in advance
Nirmala
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please exactly write your code which has given error.
then only I can understand and clarify your doubt.
------------------
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nirmala,
When you make call printArray() with integer argument, It will look for printArray(int[]) which is not defined. Look at the following code :
You make call using long[] or You overload printArray method for int[] argument.

import java.awt.*;
class Gd {
public void printArray(long a[]) {
for(int i=0;i < a.length;i++)
System.out.println(a[i]);
}
public static void main(String args[]){
long b[]={1,2,3,4};
Gd x = new Gd();
x.printArray(b); //passing long argument
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic