类型后面三个点(String...),是从Java 5开始,Java语言对方法参数支持一种新写法,叫可变长度参数列表,其语法就是类型后跟...,表示此处接受的参数为0到多个Object类型的对象,或者是一个Object[]。 例如我们有一个方法叫做test(String...strings),那么你还可以写方法test(),但你不能写test(String[] strings),这样会出编译错误,系统提示出现重复的方法。

在使用的时候,对于test(String...strings),你可以直接用test()去调用,标示没有参数,也可以用去test("aaa"),也可以用test(new String[]{"aaa","bbb"})。

另外如果既有test(String...strings)函数,又有test()函数,我们在调用test()时,会优先使用test()函数。只有当没有test()函数式,我们调用test(),程序才会走test(String...strings)。

public class Test003 {    

    private Test003(){
test();
test(new String[]{"aaa","bbb"});
test("ccc");
} private void test(){
System.out.println("test");
} private void test(String...strings){
for(String str:strings){
System.out.print(str + ", ");
}
System.out.println();
} /*private void test(String[] strings){
System.out.println(3); }*/ public static void main(String[] args) {
new Test003();
} }

jeestie框架中加载properties文件的源码:

/**
* Copyright (c) 2005-2011 springside.org.cn
*
* $Id: PropertiesLoader.java 1690 2012-02-22 13:42:00Z calvinxiu $
*/
package com.thinkgem.jeesite.common.utils; import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties; import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader; import com.google.common.collect.Maps; /**
* Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值,但以System的Property优先.
* @author calvin
* @version 2013-05-15
*/
public class PropertiesLoader { private static Logger logger = LoggerFactory.getLogger(PropertiesLoader.class); private static ResourceLoader resourceLoader = new DefaultResourceLoader(); private final Properties properties; public PropertiesLoader(String... resourcesPaths) {
properties = loadProperties(resourcesPaths);
} public Properties getProperties() {
return properties;
} /**
* 取出Property,但以System的Property优先,取不到返回空字符串.
*/
private String getValue(String key) {
String systemProperty = System.getProperty(key);
if (systemProperty != null) {
return systemProperty;
}
if (properties.containsKey(key)) {
return properties.getProperty(key);
}
return "";
} /**
* 取出String类型的Property,但以System的Property优先,如果都为Null则抛出异常.
*/
public String getProperty(String key) {
String value = getValue(key);
if (value == null) {
throw new NoSuchElementException();
}
return value;
} /**
* 取出String类型的Property,但以System的Property优先.如果都为Null则返回Default值.
*/
public String getProperty(String key, String defaultValue) {
String value = getValue(key);
return value != null ? value : defaultValue;
} /**
* 取出Integer类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常.
*/
public Integer getInteger(String key) {
String value = getValue(key);
if (value == null) {
throw new NoSuchElementException();
}
return Integer.valueOf(value);
} /**
* 取出Integer类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常
*/
public Integer getInteger(String key, Integer defaultValue) {
String value = getValue(key);
return value != null ? Integer.valueOf(value) : defaultValue;
} /**
* 取出Double类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常.
*/
public Double getDouble(String key) {
String value = getValue(key);
if (value == null) {
throw new NoSuchElementException();
}
return Double.valueOf(value);
} /**
* 取出Double类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常
*/
public Double getDouble(String key, Integer defaultValue) {
String value = getValue(key);
return value != null ? Double.valueOf(value) : defaultValue;
} /**
* 取出Boolean类型的Property,但以System的Property优先.如果都为Null抛出异常,如果内容不是true/false则返回false.
*/
public Boolean getBoolean(String key) {
String value = getValue(key);
if (value == null) {
throw new NoSuchElementException();
}
return Boolean.valueOf(value);
} /**
* 取出Boolean类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容不为true/false则返回false.
*/
public Boolean getBoolean(String key, boolean defaultValue) {
String value = getValue(key);
return value != null ? Boolean.valueOf(value) : defaultValue;
} /**
* 载入多个文件, 文件路径使用Spring Resource格式.
*/
private Properties loadProperties(String... resourcesPaths) {
Properties props = new Properties(); for (String location : resourcesPaths) { // logger.debug("Loading properties file from:" + location); InputStream is = null;
try {
Resource resource = resourceLoader.getResource(location);
is = resource.getInputStream();
props.load(is);
} catch (IOException ex) {
logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
} finally {
IOUtils.closeQuietly(is);
}
}
return props;
} public static void main(String[] args) {
Map<String, String> map = Maps.newHashMap();
PropertiesLoader loader=new PropertiesLoader("jeesite.properties");
String key="adminPath";
String value = map.get(key);
if (value == null){
value = loader.getProperty(key);
map.put(key, value != null ? value : StringUtils.EMPTY);
}
System.out.println(value);
}
}

【死磕jeestie源码】类型后面三个点(String...)和数组(String[])的区别的更多相关文章

  1. 死磕Spring源码之AliasRegistry

    死磕Spring源码之AliasRegistry 父子关系 graph TD; AliasRegistry-->BeanDefinitionRegistry; 代码实现 作为bean定义的最顶层 ...

  2. 死磕itchat源码--content.py

    content.py中定义了接受消息的类型,即,用于注册消息函数时的参数类型.源码如下: TEXT = 'Text' MAP = 'Map' CARD = 'Card' NOTE = 'Note' S ...

  3. 死磕itchat源码--目录结构

    阅读itchat源码时,先弄清itchat的目录结构 itchat │ config.py │ content.py │ core.py │ log.py │ returnvalues.py │ ut ...

  4. 死磕abstractqueuedsynchronizer源码

    第一次写博客,先练练手. 1.AQS是什么? 在Lock中,用到了一个同步队列AQS,全称为AbstractQueuedSynchronizer,它是一个同步工具也是lock用来实现线程同步的核心组件 ...

  5. 死磕itchat源码--core.py

    core.py文件中的Core类定义了itchat的所有接口.且,仅仅是定义了接口,全部在component包中实现重构.其用法如下表述: 缺省 源码如下: # -*- encoding: utf-8 ...

  6. 死磕itchat源码--config.py

    itchat的配置文件,源码: import os, platform # 版本及微信的url,二维码等 VERSION = '1.3.10' BASE_URL = 'https://login.we ...

  7. 死磕itchat源码--__init__.py

    itchat包中的__init__.py是该库的入口:在该文件中的源码如下: # -*- coding: utf-8 -*- from . import content from .core impo ...

  8. 【死磕jeesite源码】jeesite添加多数据源

    本文转载自jeesite添加多数据源 1.jeesite.properties 添加数据源信息,(url2,username2,pawwword2) #mysql database setting j ...

  9. 【死磕jeesite源码】Jeesite配置定时任务

    一.主要是注意XML文件中设置3个地方和类文件中配置 第一步配置: 第二步配置:注解扫描 第三步配置:开启任务 类中注解配置:如下 @Service 或者Component @Lazy(false) ...

随机推荐

  1. Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) (state=08S01,code=0)

    sparksql 2.和hive2.1.1 由于sparksql中的hive-cli 等包的版本是1.2的需要自己下载,下载替换之后不报错,替换之前做好备份

  2. warning: assignment from incompatible pointer type [enabled by default]

    kernel 编译产生这个警告的原因是 不兼容指针类型的赋值 这个原因很有可能是因为返回值和正在接受这个指针类型名不相同. // vim arch/arm/mach-omap2/usb-host.c ...

  3. u-boot 2016.05 添加自己的board 以及config.h

    拿到一个uboot 后,我都想添加一个属于自己的board文件以及include/configs/*.h 文件. 如何添加这个些文件,今天来记录一下. 复制一份你所参考的板级文件,比如说board/v ...

  4. 利用JDK动态代理机制实现简单拦截器

    利用JDK动态代理机制实现简单的多层拦截器 首先JDK动态代理是基于接口实现的,所以我们先定义一个接口 public interface Executer { public Object execut ...

  5. Windows 2008 Server搭建Radius服务器的方法

    原地址:http://service.tp-link.com.cn/detail_article_1113.html (图拷贝不过来) Windows 2008 Server搭建Radius服务器的方 ...

  6. Idea配置sbt(window环境)

    近开发spark项目使用到scala语言,这里介绍如何在idea上使用sbt来编译项目. 开发环境:windows 1. 下载sbt http://www.scala-sbt.org/download ...

  7. Ajax-ajax实例2-根据邮政编码获取地区信息

    项目结构 运行效果: 数据库: /* SQLyog Ultimate v12.09 (64 bit) MySQL - 5.5.53 : Database - ajaxexample_2 ******* ...

  8. 使用 OpCache 提升 PHP 5.5+ 程序性能

    说明 PHP 5.5 以后内建了 OpCache , OpCache 的加速原理是把编译后的 bytecode 存储在内存里面, 避免重复编译 PHP 所造成的资源浪费. 引用 How To Enab ...

  9. EasyUI项目中的自定义JS

    自定义方法: (function($) { $.extend($, { //获取下标,删除时使用 getArrayIndex :  function (array,value) { var index ...

  10. Semi-Supervised Classification with Graph Convolutional Networks

    Kipf, Thomas N., and Max Welling. "Semi-supervised classification with graph convolutional netw ...