Java ImmutableTriple MutableTriple 三元组件
原创 hiJerry 发表于:2021-12-29 19:19:04
  阅读 :96   收藏   编辑

依赖引入

     <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>

测试类

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.MutableTriple;
import org.junit.Test;

@Slf4j
public class AppTest {

  @Test
  public void immutableTriple() throws Exception {
    // 不可变的3元对象
    ImmutableTriple immutableTriple = ImmutableTriple.of(1,2,3);
    System.out.println(immutableTriple);
    System.out.println(immutableTriple.getLeft());
    System.out.println(immutableTriple.getMiddle());
    System.out.println(immutableTriple.getRight());
  }

  @Test
  public void mutableTriple() throws Exception {
    // 可变的3元对象
    MutableTriple mutableTriple = MutableTriple.of(1,2,3);
    System.out.println(mutableTriple);
    mutableTriple.setLeft(4);
    mutableTriple.setMiddle(5);
    mutableTriple.setRight(6);
    System.out.println(mutableTriple.getLeft());
    System.out.println(mutableTriple.getMiddle());
    System.out.println(mutableTriple.getRight());
  }
}