Java Interface Variable issues

Source: Internet
Author: User

Interfaces in Java cannot be instantiated, but it is possible to use a usage like this:

list<fileitem> items =upload.parserequest (Request); Iterator<FileItem> iter =Items.iterator ();  while(Iter.hasnext ()) {Fileitem Item=Iter.next ();File file=NewFile ("D:\\b.pdf"); if(!file.exists ()) {                        Try{file.createnewfile (); } Catch(IOException e) {e.printstacktrace (); }} bufferedoutputstream Bos=NewBufferedoutputstream (Newfileoutputstream (file));Bufferedinputstream bfis=NewBufferedinputstream (Item.getinputstream ());                    byteb[]=New byte[2048];                    intRead=bfis.read (b,0,2048);  while(Read!=-1)                      {  Bos.write (b,0, read); Read=bfis.read (b,0,2048);                    } bfis.close ();                    Bos.flush (); Bos.close ();

Mainly look at these two lines:

list<fileitem> items = upload.parserequest (request);

Iterator<fileitem> iter = Items.iterator ();

Go to the list to find source

List is the interface is not implemented, to find a implementation of the list of the class (ArrayList can)

You can see that a ITR is actually returned:

ITR is defined in the following:

A private class that implements the iterator interface. It's been clear.

Java Interface Variable issues

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.