Flex remoteobject calls java overload Functions

Source: Internet
Author: User

Flex remoteobject calls java overload Functions

Version:

Flex sdk: 3.2, jdk: 1.7; intellij idea14; flex builder3;

Problem description:

Can I call java's heavy-load method by using the remoteObject of actionscript? Is the overloaded method called?

Lab:

1. java background code:

 public  String test1(int info){        System.out.println("int:"+info);        return "int:"+info;    }    public  String test1(float info){        System.out.println("float:"+info);        return "float:"+info;    }    public  String test1(double info){        System.out.println("double:"+info);        return "double:"+info;    }    public  String test1(long info){        System.out.println("long:"+info);        return "long:"+info;    }    public  String test1(String info){        System.out.println("String:"+info);        return "String:"+info;    }
2. flex front-end code:

 

 

function testForOverload(type:String):void{if("1"==type){var info :int = 3;hDFSFileUtil.test1(info);}if("2"==type){var info2 :String = "str3";hDFSFileUtil.test1(info2);}if("3"==type){var info3:Number =new Number(33);hDFSFileUtil.test1(info3);}}
<Mx: button label = "Test 1" click = "testForOverload ('1')" visible = "true"> <mx: button label = "Test 2" click = "testForOverload ('2')" visible = "true"> <mx: button label = "Test 3" click = "testForOverload ('3')" visible = "true"> </mx: button> </mx: button>
Directly click "Test 1", "Test 2", and "Test 3" buttons and find that the called buttons are long, string, long, this indicates that the string and int/Number types in flex can be distinguished. But what type is int/Number transferred to java? Is it long?

Lab:

Adjust the positions of the first four functions in the java background and find that no matter which function, if it is in the final (normal sorting), it is called; for example, if you move the double function to the front of the string function, java calls the double function;

Summary:

This figure is from the flex4 document. We can see that when the basic type is transferred from flex to java, the int type is serialized to Integer and Number is serialized to Double, and then received on the java side. However, there are multiple types of java-side receivers;

Therefore, the conclusion is that flex can call the java-side overload function to a certain extent. (Note that flex itself does not support overloading.) However, some problems may occur; therefore, it is best to define different function names;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.