Problems

Use the following problems to test your type inference programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:

  1. Simple var example: Write a program that exemplifies the correct usage of type inference (var) with respect to the code's readability.
  2. Using var with primitive types: Write a program that exemplifies the usage of var with Java primitive types (int, long, float, and double).
  3. Using var and implicit type casting to sustain the code's maintainability: Write a program that exemplifies how var and implicit type casting can sustain the code's maintainability.
  4. Explicit downcast or better avoid var: Write a program that exemplifies the combination of var and explicit downcast and explain why var should be avoided.
  5. Avoid using var if the called names don't contain enough type information for humans: Provide examples where var should be avoided because its combination with called names causes loss of information for humans.
  6. Combining LVTI and programming to the interface technique: Write a program that exemplifies the usage of var via the programming to the interface technique.
  1. Combining LVTI and the diamond operator: Write a program that exemplifies the usage of var with the diamond operator.
  2. Assigning an array to var: Write a program that assigns an array to var.
  3. Using LVTI in compound declarations: Explain and exemplify the usage of LVTI with compound declarations.
  4. LVTI and variable scope: Explain and exemplify why LVTI should minimize the variable's scope as much as possible.
  5. LVTI and the ternary operator: Write several snippets of code that exemplify the advantages of combining LVTI and the ternary operator.
  6. LVTI and for loops: Write several examples that exemplify the usage of LVTI in for loops.
  7. LVTI and streams: Write several snippets of code that exemplify the usage of LVTI and Java streams.
  8. Using LVTI to break up nested/large chains of expressions: Write a program that exemplifies the usage of LVTI for breaking up a nested/large chain of expressions.
  9. LVTI and the method return and argument types: Write several snippets of code that exemplify the usage of LVTI and Java methods in terms of return and argument types.
  10. LVTI and anonymous classes: Write several snippets of code that exemplify the usage of LVTI in anonymous classes.
  11. LVTI can be final and effectively final: Write several snippets of code that exemplify how LVTI can be used for final and effectively final variables.
  12. LVTI and lambdas: Explain via several snippets of code how LVTI can be used in combination with lambda expressions.
  13. LVTI and null initializers, instance variables, and catch blocks variables: Explain with examples how LVTI can be used in combination with null initializers, instance variables, and catch blocks.
  14. LVTI and generic types, T: Write several snippets of code that exemplify how LVTI can be used in combination with generic types.
  15. LVTI, wildcards, covariants, and contravariants: Write several snippets of code that exemplify how LVTI can be used in combination with wildcards, covariants, and contravariants.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.178.237