private long getParameter(String s, long l)
如果s!=null,返回它的long值(转换了一下);否则,返回lprivate String getParameter(String s, String s1)
如果s!=null,返回s,否则返回s1

解决方案 »

  1.   

    关键是我想知道
    String s1 = getParameter(s);
    String s2 = getParameter(s);
    这两句话分别调用哪个函数
    这样写为什么不算错
    难道参数可以不用写全吗?
      

  2.   

    在传递参数的时候,如果只有s参数,则函数调用
    将l和sl初始化为0和null。
    所以只和s有关系
      

  3.   

    源代码:
    package weblogic.management.console.applets;import java.applet.Applet;
    import java.applet.AppletContext;
    import java.awt.*;
    import java.io.IOException;
    import java.io.PrintStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.Vector;
    public final class NavApplet extends Applet
        implements Runnable
    {    private static final long serialVersionUID = 0x7f3e0b5c079eddb3L;
        private static final String DEFAULT_ENCODING = null;
        private static boolean FORCE_DEBUG = false;
        static boolean DEBUG = false;
        private static final String DEBUGON = "debug";
        private static final String ENCODING = "encoding";
        private static final String TARGETFRAME = "target";
        private static final String TREESERVLET = "TreeServlet";
        private static final String EXPANDED = "ExpandedIcon";
        private static final String COLLAPSED = "CollapsedIcon";
        private static final String SESSIONID = "JSESSIONID";
        private static final String PARAMS[][] = {
            {
                "TreeServlet", "String", "URL from which to populate the tree."
            }, {
                "ExpandedIcon", "String", "URL of the expander image."
            }, {
                "CollapsedIcon", "String", "URL of the collapser image."
            }, {
                "JSESSIONID", "String", "WebLogic Session ID."
            }, {
                "encoding", "String", "Character encoding to use for parsing nav page."
            }, {
                "debug", "String", "Send debugging output to console."
            }
        };
        private static Vector mOpenIds = null;
        private String mDefaultServer;
        private String mTreeServlet;
        private String mSessionId;
        private String mEncodingType;
        private ImageCatalog mImageCatalog;
        private TreeNode mRoot;
        private NavPanel mNavPanel;
        private boolean mIsLoading;    public NavApplet()
        {
            mIsLoading = false;
        }    private void checkParams()
        {
            String as[][] = getParameterInfo();
            for(int i = 0; i < as.length; i++)
                if(!as[i][0].equals("debug"))
                    if(getParameter(as[i][0]) == null)
                        debug("Expected parameter '" + as[i][0] + "' not specified in <APPLET> tag, " + "applet may not function correctly.");
                    else
                        debug("Read parameter '" + as[i][0] + "=" + getParameter(as[i][0]) + "'");    }    private void debug(String s)
        {
            if(FORCE_DEBUG || DEBUG)
            {
                getAppletContext().showStatus(s);
                System.out.println(s);
            }
        }    private void fetchTree(String s, Vector vector)
            throws MalformedURLException, IOException, Exception
        {
            if(!s.startsWith("http://") && !s.startsWith("https://"))
                s = mDefaultServer + s;
            debug("fetching tree from " + s);
            mRoot = new TreeNode();
            TreeParser treeparser = new TreeParser(mImageCatalog, mSessionId, vector, mEncodingType, getAppletContext());
            treeparser.parse(s, mRoot);
            debug("waiting for any new images...");
            try
            {
                mImageCatalog.waitForAll(10000L);
            }
            catch(InterruptedException interruptedexception)
            {
                interruptedexception.printStackTrace();
            }
            mNavPanel.setRoot(mRoot);
            debug("tree loaded.");
        }    private long getParameter(String s, long l)
        {
            String s1 = getParameter(s);
            if(s1 != null)
                try
                {
                    return (long)Integer.parseInt(s1);
                }
                catch(Exception _ex) { }
            return l;
        }    private String getParameter(String s, String s1)
        {
            String s2 = getParameter(s);
            if(s2 != null)
                return s2;
            else
                return s1;
        }    public String[][] getParameterInfo()
        {
            return PARAMS;
        }    public void init()
        {
            debug("Initializing Nav Applet...");
            String s = getParameter("debug");
            DEBUG = s != null && s.equalsIgnoreCase("true");
            if(DEBUG)
                checkParams();
            URL url = getCodeBase();
            mDefaultServer = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
            debug("Default Server is " + mDefaultServer);
            String s1 = getParameter("ExpandedIcon");
            String s2 = getParameter("CollapsedIcon");
            String s3 = getParameter("target");
            mSessionId = getParameter("JSESSIONID");
            mImageCatalog = new ImageCatalog(this, mDefaultServer);
            setLayout(new BorderLayout());
            try
            {
                java.awt.Image image = mImageCatalog.fetch(s1);
                java.awt.Image image1 = mImageCatalog.fetch(s2);
                mNavPanel = new NavPanel();
                mNavPanel.init(getAppletContext(), image, image1, mDefaultServer, s3);
                add(mNavPanel, "Center");
                mEncodingType = getParameter("encoding");
                if(mEncodingType == null || mEncodingType.trim().length() == 0)
                    mEncodingType = null;
                mTreeServlet = getParameter("TreeServlet");
                if(mTreeServlet != null)
                    fetchTree(mTreeServlet, mOpenIds);
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
            setAppletFrameNameForWinRunner("WeblogicConsoleNavigationAppletFrame");
        }    public void reload()
        {
            if(!mIsLoading)
                (new Thread(this)).start();
        }    public void run()
        {
            mIsLoading = true;
            try
            {
                mOpenIds = new Vector();
                mRoot.getOpenIds(mOpenIds);
                fetchTree(mTreeServlet, mOpenIds);
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
            mIsLoading = false;
        }    private void setAppletFrameNameForWinRunner(String s)
        {
            try
            {
                Container container = null;
                Container container1 = getParent();
                debug("Attempting to reset parent applet frame's name to " + s);
                int i = 0;
                byte byte0 = 5;
                while((container = container1.getParent()) != null && i < 5) 
                {
                    debug("Parent " + i++ + ": " + container1.toString());
                    container1 = container;
                }
                debug("Applet has " + i + " parent containers");
                if(container1 != null)
                {
                    debug("Current parent name is " + container1.getName());
                    container1.setName(s);
                    debug("New parent name is now " + container1.getName());
                }
            }
            catch(Throwable throwable)
            {
                debug("Caught exception during debug: " + throwable);
            }
        }    public void setSize(int i, int j)
        {
            super.setSize(i, j);
            super.resize(i, j);
            debug("setting size to " + i + " " + j);
            invalidate();
            validate();
            doLayout();
            repaint();
            mNavPanel.forceRefresh();
        }    public void stop()
        {
            debug("stop() called, saving list of open nodes...");
            mOpenIds = new Vector();
            mRoot.getOpenIds(mOpenIds);
        }}
      

  4.   

    是函数的重载
    一定有一个函数是这样定义的:
    String getParameter(String s);
      

  5.   

    可是我没有看见有String getParameter(String s);
    这样的函数定义啊。。
    :(
      

  6.   

    还没有,我想知道Java能不能按返回值来自动判断使用哪个函数