Java 배우기145 Unbounded Wildcards 언바운디드 와일드카드 언바운디드 와일드카드 Unbounded Wildcards The unbounded wildcard type is specified using the wildcard character (?), for example, List. This is called a list of unknown type. There are two scenarios where an unbounded wildcard is a useful approach:If you are writing a method that can be implemented using functionality provided in the Object class.When the code is using methods in the generic class that do.. 2016. 1. 24. Upper Bounded Wildcards 어퍼 바운디드 와일드카드 어퍼 바운디드 와일드카드 Upper Bounded Wildcards You can use an upper bounded wildcard to relax the restrictions on a variable. For example, say you want to write a method that works on List, List, and List; you can achieve this by using an upper bounded wildcard.To declare an upper-bounded wildcard, use the wildcard character ('?'), followed by the extends keyword, followed by its upper bound. Note that, .. 2016. 1. 24. Wildcards 와일드카드 와일드카드 Wildcards 제네릭 코드에서, 와일드카드 라고 하는 물음표 (?)는 알 수 없는 타입을 나타냅니다. 와일드카드는 다양한 상황에서 사용될 수 있습니다: 매개변수의 타입, 필드 또는 로컬변수로; 때로는 반환 타입으로 (보다 구체적인 프로그래밍 습관이 바람직하지만). 와일드카드는 제네릭 메소드 호출에 대한 타입 아규먼트, 제네릭 클래스 인스턴스 생성 또는 슈퍼타입으로 는 사용되지 않습니다.다음 섹션에서는 상위 경계 와일드카드, 낮은 경계 와일드카드 및 와일드카드 캡처를 포함한 와일드카드를 보다 상세하게 설명합니다.In generic code, the question mark (?), called the wildcard, represents an unknown type. The wildcard .. 2016. 1. 24. Type Inference 타입 인퍼런스 타입 인퍼런스 Type Inference Type inference는, 각각의 메소드 호출(invocation) 및 해당되는 호출을 만드는 타입 아규먼트 (또는 아규먼트들)를 결정하는 상응하는 선언을 볼 수 있게 하는 자바 컴파일러의 능력입니다. The inference algorithm determines the types of the arguments and, if available, the type that the result is being assigned, or returned. Finally, the inference algorithm tries to find the most specific type that works with all of the arguments.To illustrate t.. 2016. 1. 24. Generics, Inheritance, and Subtypes Generics, Inheritance, and SubtypesAs you already know, it is possible to assign an object of one type to an object of another type provided that the types are compatible. For example, you can assign an Integer to an Object, since Object is one of Integer's supertypes:Object someObject = new Object(); Integer someInteger = new Integer(10); someObject = someInteger; // OK In object-oriented termi.. 2016. 1. 24. Generic Methods and Bounded Type Parameters Generic Methods and Bounded Type ParametersBounded type parameters are key to the implementation of generic algorithms. Consider the following method that counts the number of elements in an array T[] that are greater than a specified element elem.public static int countGreaterThan(T[] anArray, T elem) { int count = 0; for (T e : anArray) if (e > elem) // compiler error ++count; return count; } .. 2016. 1. 24. 이전 1 2 3 4 5 6 7 8 ··· 25 다음