본문 바로가기

Java 배우기145

Lambda Expressions 람다 표현식 람다 표현식 Lambda Expressions 익명 클래스의 문제 중 하나는, 메소드가 1개만 포함된 interface인 경우 처럼 익명 클래스 구현이 매우 간단한 경우, 익명 클래스의 구문규칙을 다루기 힘들고 불분명해 보일 수 있다는 점입니다. 위와 같은 경우, 어떤 사람이 버튼을 클릭하면 작업이 수행되도록 하는 것처럼, 일반적으로 functionality를 아규먼트로써 다른 메소드에게 전달하려 합니다. 람다 표현식은 functionality를 메소드 아규먼트로 처리하여, 또는 코드를 데이터로 처리하여 이것이 수행될 수 있게 만들어줍니다. One issue with anonymous classes is that if the implementation of your anonymous class is ve.. 2016. 1. 5.
Anonymous Classes 익명 클래스 익명 클래스 Anonymous Classes 익명 클래스를 이용하면 코드를 보다 간결하게 작성할 수 있습니다.익명 클래스를 이용하면 동시에 클래스를 선언하고 인스턴스화할 수 있습니다. 익명 클래스들은 이름이 없는 것을 제외하고는 로컬 클래스와 같습니다.로컬 클래스를 단 한 번 사용해야 할 경우라면 익명 클래스를 사용하십시오.이 섹션은 다음 토픽들을 다룹니다:Anonymous classes enable you to make your code more concise. They enable you to declare and instantiate a class at the same time. They are like local classes except that they do not have a name. Us.. 2016. 1. 5.
Local Classes 로컬 클래스 로컬 클래스 Local Classes 로컬 클래스들은 블록 안에 정의된 클래스들로써, 중괄호 안의 하나 이상의 선언문의 그룹입니다. 일반적으로 메소드의 몸체 안에 정의된 로컬 클래스들이 있습니다. 이 섹션은 다음 토픽을 다룹니다: Local classes are classes that are defined in a block, which is a group of zero or more statements between balanced braces. You typically find local classes defined in the body of a method. This section covers the following topics:로컬 클래스 선언하기 Declaring Local Classes인크로.. 2016. 1. 5.
Inner Class Example 내부 클래스 예제 내부 클래스 예제 Inner Class Example 사용되는 inner class를 보기 위하여, 우선 array를 검토합니다. 다음 예제에서, array를 만들고, array를 integer values로 채우고, 그런 다음 ascending 순서로 only values of even indices of the array 를 output 합니다.The DataStructure.java example that follows consists of: To see an inner class in use, first consider an array. In the following example, you create an array, fill it with integer values, and then outpu.. 2016. 1. 5.
Nested Classes Nested Classes 자바 프로그래밍 언어에서는 다른 클래스 안에 클래스를 정의할 수 있습니다. 다른 클래스 안에 정의된 클래스를 nested class 라고 하며 아래 그 예가 있습니다: The Java programming language allows you to define a class within another class. Such a class is called a nested class and is illustrated here:class OuterClass { ... class NestedClass { ... } } 용어: Nested 클래스는 2개의 카테고리로 구분됩니다: static과 non-static. static으로 선언된 종속 클래스를 static nested classes.. 2016. 1. 5.
Questions and Exercises: Objects Questions and Exercises: ObjectsQuestionsWhat's wrong with the following program?public class SomethingIsWrong { public static void main(String[] args) { Rectangle myRect; myRect.width = 40; myRect.height = 50; System.out.println("myRect's area is " + myRect.area()); } } The following code creates one array and one string object. How many references to those objects exist after the code executes.. 2016. 1. 5.