2021. 3. 29. 16:41ㆍData science
All local variable declarations required an explicit type on the left side
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-> Explicit type can be replaced by the reserved type name var
-> var outputStream = new ByteArrayOutputStream();
해설)
1) Line 11: Var to Declare the name field. But there is not enough context to infer the data type.
2) Line 12: Var to declare the breed field. Enough context. We can guess the breed is String. However, the scope of Var should be extremely limited. The scope of fields is not. So this is not correct.
3) Line 14: Var to declare the parameters. Var is not allowed for parameter type.
4) Line 20: Var can be used within a for-loop. And the type is inferred based on the collection we specify when the for-loop is declared.
해설)
1) A is an ArrayList of objects, not strings ->charAt method call is not valid. If the string was used instead of Var, it may have worked. (not enough context to say this is the list of string objects.)
2) This one has enough context to say this is the list of string objects as the ArrayList has been said that it's a type of <string>. This makes the last line valid(charAt)
3) Created the string directly at the first line. And inferring charAt on the second line.
4) var is not a keyword, it is a reserved type name.
5) double is a keyword, it is not allowed to use it as a variable.
**What is LAMBDA?
A Lambda expression is a short block of code that takes in parameters and returns a value. It's similar to methods, but they do not need a name and they can be implemented right in the body of a method.
It provides a clear and concise way to represent one method interface using an expression. It is very useful in collection library. IT helps to iterate, filter and extract data from the collection.
해설)
1) A,B, and C is needed the parentheses.
2) C also the parameter type to be declared
3) var can be declared final. -> so this is correct
4) must declare them all with a var
5) correct
'Data science' 카테고리의 다른 글
[빅분기] 1과목 1장 3 빅데이터 산업의 이해 (0) | 2021.03.30 |
---|---|
[Oracle_Java] Java SE: Programming Complete_01 (0) | 2021.03.30 |
[ORC_Java Prep] 1. Java SE 11 Certification (0) | 2021.03.29 |
[빅분기] 1과목 1장 2 빅데이터 가치 (0) | 2021.03.28 |
[빅분기] 1과목 1장 1 빅데이터의 특징 (0) | 2021.03.28 |