• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

(WhatIsThis)ab.remove(0); // Syntax question

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please explain to me what is happening when a method call is prefaced by parenthesis, such as shown in the example in the subject?

The ab.remove(0); part I get. I don't understand the (WhatIsThis) part.

Thanks!
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the (whatIsThis) happens to be the name of a data type, such as (int) or (double) or the like, then you're probably looking at a typecast.

that is, the method returns a value of some one type, but the place where the method call is used needs a value of another type. putting the name of the type you need in parentheses before the method call like that tells the javac compiler to try and convert the value returned into the type needed, as best it can.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, when an expression is preceded by something in parentheses, this means that the object reference (or primitive value) represented by that expression is explicitly cast to the type specified within the parentheses.


For example, in an ArrayList, the remove(int) method returns a reference to the element removed from the List at the specified index (the int argument). But this reference is likely to be of type Object; so to be of any use, it needs to be explicitly cast back to its true type.
[ January 18, 2005: Message edited by: marc weber ]
 
Charles McGuire
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! With this information, I returned to the code and it makes perfect sense now.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic