Guava

weixin_34248705發表於2017-12-12
  • ImmutableList

用ImmutableList構建List:

import com.google.common.collect.ImmutableList;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class ImmutableListStudyTest {

  @Test
  public void test_Immutable_List() throws Exception {
    List<Object> params = ImmutableList.builder()
            .add(1)
            .add("2")
            .add(3L)
            .build();

    assertEquals(params.get(0), 1);
    assertEquals(params.get(1), "2");
    assertEquals(params.get(2), 3L);
  }
}

compile group: 'com.google.guava', name: 'guava', version: '23.5-jre

相關文章