473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Meaning of notation (Type)variable

Hello,
I am planning to program an Xml displayer that will show an Xml file
in a tree view. This will involve the development of a tailored tree
model which will use DOM nodes instead of the DefaultMutableTreeNode.
To get an idea of how a tree model can be generated, I have downloaded
an example from the sun homepage in which file objects are used as
TreeNodes. This program resembles mine in that the tree will be
constructed from objects which are differnt from the standard TreeNode
object. HOwever, I think that I have not yet got a very basic conecept
of Java, because I do not know what e.g. the following lines mean
<Snip>
public boolean isLeaf(Object node) { return ((File)node).isFile();
}

public int getChildCount(Object parent) {
String[] children = ((File)parent).list();
if (children == null) return 0;
return children.length;
}
</Snip>
particular the notation "((File)node)".
The isLeaf function receives an "Object" as argument which probably
does not have an "isFile" method. So does the expression ((File)node)
gives some of the methods for "File" objects to the general "Object"
object? How is this language feature called, because I have frequently
seen lines like this and I would like to understand that topic.
Thanks in advance
Peter
Jul 17 '05 #1
1 1680
pi********@gmx.de (Piet) wrote in news:39cbe663.0406151233.12a75385
@posting.google.com:

<SNIP>
of Java, because I do not know what e.g. the following lines mean
<Snip>
public boolean isLeaf(Object node) { return ((File)node).isFile();
}

public int getChildCount(Object parent) {
String[] children = ((File)parent).list();
if (children == null) return 0;
return children.length;
}
</Snip>
particular the notation "((File)node)".

<SNIP>

This is a fairly basic concept in Java; you need to learn this!

This is known as a cast. See http://mindprod.com/jgloss/cast.html
for a further explanation. (Thanks, Roedy!) Be sure to follow up the four
references (in red at the bottom of the article).

In the case of "(File)node", "node" had better be of actual type "File" (or
of a subclass of "File"). If it is, then it will have an "isFile()" method
(either from "File" or overridden by the subtype). If "node" is NOT of
type "File" or a subclass of it, then an exception "ClassCastException"
will occur.

--
Ian Shef
These are my personal opinions and not those of my employer.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fred Zolar | last post by:
Anyone know how to cast an object to the type stored in a System.Type variable? I need to cast m_oValue to an int, bool, ect... based on the variable Type. public class TestClass { private...
4
by: Ramez | last post by:
Hi I need to create an object of a class using a type variable. for example, instead of writing: X = new MyClass I want to write something like: Dim t as Type = GetType(MyClass) X =...
0
by: Ramez | last post by:
Hi I need to create an object of a class using a type variable. for example, instead of writing: X = new MyClass I want to write something like: Dim t as Type = GetType(MyClass) X =...
2
by: hisham123 | last post by:
hi, I Wrote one stored procedure in which i declare one variable as Table then i stored in that table type variable select * from emp so now my table contain one sql statement by 4 rows...
5
by: raghunadhs | last post by:
Hi All, How can i write a Dynamic query so that i can hold a varchar type variable also? please see the below sample example what i have written.. Declare @varSql varchar(2000) Declare...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.