
Calling Java Objects
381
•
Java method and field names are not case sensitive. Similarly, ColdFusion
variables are not case sensitive. As a result, the sample code works even though
the CFML uses emp.firstname and emp.lastname, while the Java source code
uses FirstName and LastName for these fields.
•
If you omit a call to the constructor (or, as in this example, comment it out)
ColdFusion automatically invokes the default constructor when it first uses the
class.
Using an alternate constructor
The following CFML page explicitly calls one of the alternate constructors for the
Employee object:
<html>
<body>
<cfobject action=create type=java class=Employee name=emp>
<cfset emp.init("John", "Doe",100000.00, 10 )>
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
<cfset salary=emp.GetSalary()>
<cfset grade=emp.GetJobGrade()>
</body>
<cfoutput>
Employee name is #firstname# #lastname#
Employee salary and Job Grade #Salary# #grade#
</cfoutput>
</html>
In this example, the constructor takes four arguments; the first two are strings, and
third is a float, and the fourth is an integer.
Java and Cold Fusion Data Type Conversions
Cold Fusion is a typeless scripting language (that is, it does not use explicit data
types) while Java is strongly typed.
Under most situations, when the method names are not ambiguous, ColdFusion can
determine the required types. For example, ColdFusion strings are implicitly
converted to the Java String type. Similarly, if a Java object contains a doIt method
that expects a parameter of type int, and CFML is issuing a doIt call with a CFML
variable x, ColdFusion will converts the variable x to Java int type. However,
ambiguous situations can result from Java method overloading, where a class has
multiple implementations of the same method that differ only in their parameter
types.
The following sections describe how ColdFusion handles the unambiguous
situations, and how it provides you with the tools to handle ambiguous ones.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...