首页>代码>《java组件设计》书籍配套代码>/java组件设计-配套代码/tijcd/ch3/generic/GenericBound.java
/*
 * Source code of the book of Thinking in Java Component Design
 * 中文书名:Java 组件设计
 * 作者: 孔德生
 * Email: kshark2008@gmail.com
 * Date: 2008-12
 * Copyright 2008-2010
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package generic;

import java.util.*;

public class GenericBound<T extends BaseClass> {
	
	public long sum(List<T> tList) {
		long iValue = 0;
		for (BaseClass base : tList) {
			iValue += base.getValue();
		}
		
		return iValue;
	}

	public static void main(String[] args) {
		GenericBound<SubClass> obj = new GenericBound<SubClass>();
		
		List<SubClass> list = new LinkedList<SubClass>();
		list.add(new SubClass(5));
		list.add(new SubClass(6));
		
		System.out.println(obj.sum(list));
	}
}
最近下载更多
linmou  LV8 2023年3月19日
yuandi22  LV1 2022年12月8日
caohanren  LV11 2021年11月30日
amojohn  LV2 2021年9月10日
国服第一程序员  LV3 2021年4月14日
2196316269  LV10 2021年2月25日
lizhenlinok  LV10 2021年1月11日
moomin709  LV24 2020年5月9日
25462331106  LV3 2020年5月8日
安安an  LV17 2020年1月9日
最近浏览更多
linmou  LV8 2023年3月19日
yuandi22  LV1 2022年12月8日
1306878374  LV13 2021年12月26日
caohanren  LV11 2021年11月30日
1394564216  LV2 2021年11月25日
你脚上银铃响了  LV1 2021年10月27日
tangjj7260  LV18 2021年10月26日
amojohn  LV2 2021年9月10日
国服第一程序员  LV3 2021年4月14日
2196316269  LV10 2021年2月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友