java元组
来源:互联网 发布:微信二级分销系统源码 编辑:程序博客网 时间:2024/05/20 02:55
元组是将一组对象直接打包存储于其中的一个单一对象。
这个容器对象允许读取其中元素,但是不允许向其中放入新的对象。
下面是一个二维元组,能够持有两个对象:
public class TwoTuple<A,B> { //first可以访问,但不可以被赋值 public final A first; public final B second; public TwoTuple(A a,B b){ first=a; second=b; } public String toString(){ return "("+first+","+second+")"; }}
扩大元组:
public class ThreeTuple<A,B,C> extends TwoTuple<A,B>{ public final C third; public ThreeTuple(A a, B b,C c) { super(a, b); third=c; } public String toString(){ return "("+first+","+second+","+third+")"; }}
测试:
class Amphibian{}public class TupleTest { static TwoTuple<String,Integer> f(){ return new TwoTuple<String,Integer>("hi",47); } static ThreeTuple<Amphibian,String,Integer> g(){ return new ThreeTuple<Amphibian,String,Integer>(new Amphibian(),"hi",47); } public static void main(String[] args){ TwoTuple<String,Integer> ttsi=f(); System.out.println(ttsi); //ttsi.first="there";//错误,final无法修改 System.out.println(g()); }}
阅读全文
0 0
- java Tuple 元组
- Java元组
- java元组
- java 使用自定义元组
- Java 泛型 元组的使用
- Java元组Tuple介绍与使用
- Java的元组类型整理
- 元组
- 元组
- 元组
- 元组
- 元组
- 元组
- 元组
- 元组
- 元组
- 元组
- 元组
- 算法提高 ADV-155 上帝造题五分钟
- SVN Working copy locked Please execute the 'Cleanup' command.
- 集合-hashCode
- .h头文件和.a静态库文件问题记录
- Vue数组检测
- java元组
- Jni/NDK常见问题
- 构造函数与析构函数
- 机器学习深入与强化--数学基础(2)
- 纪念第一次深度学习跑通
- hive简介——java连接和数据管理的方式
- css常用标签英文全称
- vijos1059-背包计数-积木城堡
- 算法提高 ADV-162 题目1 最大最小值