[JAVA] Introduction (editing)

About the basics of generics


List<String> list = new ArrayList<>();
list.add(1); //Compile error

-[x] You can specify the type to be included in List

Prohibiting new type variable E in generic typeclass

class Owner<E>{
  E createObject(){
    return new E();

Compile error

-[] Task 1 -[x] Task 2


type parameter The variable part inside
Type variable
Variables qualified as type parameters
type argument
The specific type to pass to <> when using a generic type. String part of List
Parameterized type
type A type that can actually be used by passing an argument. List itself

When you declare List

class List<String> {
	private String element;
	String get() {
		return element;
	void put(String e) {
		this.element = e;

Is created internally. (Unsettled)

Recommended Posts

Introduction (editing)
Lombok ① Introduction
Introduction (self-introduction)
[Java] Introduction
Introduction to Ruby 2
Spring Fox ① Introduction
Rspec introduction memo_Rails
Functional interface introduction
Introduction (editing)
Introduction of milkode
[Rails 6] cocoon_ introduction
About MacinCloud introduction
Introduction to web3j
[Java] Introduction to Java
Introduction to migration
Introduction to java
Introduction to Doma
Ractor super introduction