Java static method using notes

Source: Internet
Author: User

static method with incoming arguments, can be used normally

The function of static is to affirm: This is the static method of the class, when all can be called, can pass in the parameter, also can not pass.

On the code:

1. Classes with static methods:

 Public class makeparameters {    publicstatic  INSURANCESEARCHRQ makebaserqparms ( INSURANCESEARCHRQ RQ) {        new  channelinfo ();        Channel.setfirstchannelno (baseconst.first_channel_no);        Channel.setwebsite (baseconst.web_site);                Rq.setchannelinfo (channel);        Rq.setlanguage (BASECONST.LANGUAG);        Rq.settimestamp (baseconst.timestamp);        Rq.settransactionid (baseconst.transaction_id);        Rq.setversion (baseconst.version);                     return RQ;    }}
View Code

2. Test class:

  

 PackageCom.doit.zz;Importorg.junit.Test;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;Importcom.basemake.zz.MakeParameters;ImportCom.travelsky.logic.insurance.dto.InsuranceSearchRQ;ImportCom.travelsky.logic.insurance.dto.InsuranceSearchRS;ImportCom.travelsky.logic.insurance.dto.MaintainQueryParam;ImportCom.travelsky.logic.shopping.service.IInsuranceSearchService;ImportCom.utils.zz.JsonMapper; Public classinsuretest {applicationcontext ctx=NewClasspathxmlapplicationcontext ("Helloservice.xml"); @Test Public voidTestinsure ()throwsexception{INSURANCESEARCHRQ RQ=NewINSURANCESEARCHRQ (); Maintainqueryparam Maintainqueryparam=NewMaintainqueryparam (); Maintainqueryparam.setproductcode ("7000000");        Rq.setmaintainqueryparam (Maintainqueryparam);        Makeparameters.makebaserqparms (RQ); System.out.println (Jsonmapper.tononnulljson (RQ));//1Maintainqueryparam.setproductcode ("12345"); INSURANCESEARCHRQ RQ2=NewINSURANCESEARCHRQ ();                Rq2.setmaintainqueryparam (Maintainqueryparam);        Makeparameters.makebaserqparms (RQ2); System.out.println (Jsonmapper.tononnulljson (RQ2));//2insurancesearchrs rs=Newinsurancesearchrs (); Iinsurancesearchservice Insservice= (Iinsurancesearchservice) ctx.getbean ("Iinsurancesearchservice"); RS=insservice.getinsurancesearchrs (RQ); String Rsjson=Jsonmapper.tononnulljson (RS);                System.out.println (Rsjson); }        }
View Code

3. Results

{"Channelinfo": {"Firstchannelno": "", "" WebSite ":" ZH_CN "}," TimeStamp ":" 20150108161025 "," Version ":" 0.01 "," TransactionID ":" 20150108161025 "," language ":" zh "," Instravelerinfos ": []," Maintainqueryparam ": {" ProductCode ":" 7000000 "}}
{"Channelinfo": {"Firstchannelno": "", "" WebSite ":" ZH_CN "}," TimeStamp ":" 20150108161025 "," Version ":" 0.01 "," TransactionID ":" 20150108161025 "," language ":" zh "," Instravelerinfos ": []," Maintainqueryparam ": {" ProductCode ":" 12345 "}}

Static method results are called at 1 and 2 out of separate print

You can see: Two calls to static methods: The arguments are different, and the results are different.

Java static method using notes

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.