Parameter passing mechanism in java

Problems encountered

After the recent experience in learning TOMCAT some problems, such as request request socket.inputstream, after performing the resolution, forget inputstream re-assignment, or inputStream request request before use, and then found the problem to print two output streams, which see different types, one is adapted TOMCAT connector class, the other is an input stream of bytes, and finally viewed by a third-party library found to have incorporated a byte [in his class DiskFileItem] cachedContent so guess would be to use this as a request from the incoming request inputstream is located.

            DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
            ServletFileUpload servletFileUpload = new ServletFileUpload(fileItemFactory);
            List<FileItem> fileItems = servletFileUpload.parseRequest(request);
            InputStream inputStream1 = fileitem.getInputStream();//必须要获取这个inputstream,因为在传值的过程中已经对其中的输出流进行了读取
            System.out.println(inputStream);
            System.out.println(inputStream1);
/*
org.apache.catalina.connector.CoyoteInputStream@3a5e9fb2
java.io.ByteArrayInputStream@7f5c169d
*/

When the request is passed as a parameter, in the stack frame of the other methods will request a copy of the reference address, so it can modify the request.

java parameter passing mechanism

Parameter passing mechanism in the method java

Parameter passing mechanism in the method java

Why only passed by value in Java

Guess you like

Origin www.cnblogs.com/innndown/p/12408545.html