Java: Working with Annotations, Generics, & Arrays Using Reflection
Java
| Expert
- 10 videos | 1h 26m 30s
- Includes Assessment
- Earns a Badge
Annotations on Java code allow you to associate additional metadata with classes, member variables, constructors, and methods. These annotations can be used to perform additional checks or add functionality to your Java code. Use this course to practice using annotations with reflection. Work with both built-in and custom annotations and see how you can access the annotations applied on classes, fields, and methods. Learn why not all annotations can be accessed via reflection. Create your own custom annotation and experiment with various retention policies. Next, examine accessing generics and arrays with reflection. When you're finished, you'll be able to harness the power of reflection to add new functionality to your code and work with generics and arrays.
WHAT YOU WILL LEARN
-
Discover the key concepts covered in this courseExamine what built-in annotations are accessible using reflectionCreate a custom annotation and examine retention policiesImplement a use-case for reflection - accessing annotations to perform checksImplement a use-case for reflection - using reflection to check the objects of classes for validity
-
Identify what generic information about type parameters is available using reflectionExplore the disadvantages of using reflection with genericsView and edit data stored in arraysUse reflective access to determine array types and component typesSummarize the key concepts covered in this course
IN THIS COURSE
-
2m 41sThis course will provide you with an in-depth exploration of the use of annotations and how they work with reflection. You’ll learn built-in and custom annotations and see how annotations on an object or a method can be picked up using reflection. You’ll learn that not all annotations can be picked up by reflection. You’ll learn more about the retention policy of an annotation. You’ll then learn about generics. FREE ACCESS
-
9m 41sHere, you’ll watch a demo on how to access annotations on fields and methods. Annotations in Java can be thought of as code elements used to annotate or decorate other bits of code like classes, parameters, return types, or type parameters. This demo will focus on the relationship between reflection and annotations. FREE ACCESS
-
12m 13sHere, you’ll watch a demo on configuring custom annotations for reflective access. You’ll learn some types of annotations are not preserved for reflective access. This is due to a property called the retention policy. In this demo, you’ll see how the retention policy works. To do so, you’ll create your own annotation objects. These are known as custom annotations. FREE ACCESS
-
11m 50sIn this demo, you’ll learn how to access annotations to perform checks. You’ll learn how to define a custom annotation. Then, you’ll use this annotation to impose a constraint on a field in your class. You’ll then use reflection in order to check whether this constraint has been satisfied or not. This will demonstrate how a combination of annotations and reflection can be used to monitor and regulate the state of your program. FREE ACCESS
-
11m 27sHere, you’ll watch a demo. You’ll learn how to check objects for vitality. You’ll write and run code in this demo. Running this code will allow you to use reflection along with annotations. FREE ACCESS
-
9m 34sHere, you’ll watch a demo. You’ll learn to use reflection with generic classes and methods. You’ll see how reflection works in the context of type parameters and parametrized classes. You’ll use a file called Container.java, which is a class that’s parameterized. FREE ACCESS
-
11m 4sHere, you’ll watch a demo. You’ll explore the limitations of reflections and generics. You’ve seen the limitations of the Java reflection APIs when it comes to detecting type parameters used with local variables in your Java code. There are many different methods in the Java API such as .toGenericString, .getSuperclass, .getGenericSuperclass. But none of these are consistent when detecting the type parameter of a generic class object. You’ll take a different approach here. FREE ACCESS
-
7m 43sHere, you’ll watch a demo. You’ll learn to use reflection when working with arrays. You’ll learn how arrays can be used, instantiated, and queried using reflection. You’ll create some arrays of reference types. FREE ACCESS
-
8m 11sHere, you’ll watch a demo. You’ll explore array types and component types. You’ll turn your attention to multi-dimensional arrays. You’ll work with code that creates multi-dimensional int arrays. FREE ACCESS
-
2m 9sThis course provided you with an in-depth exploration of the use of annotations with reflection. You learned about built-in and custom annotations and saw how to access the annotations on an object or method. You also learned the retention policy of annotation and that only annotations with a retention policy of runtime can be accessed via reflection. You created custom annotation and experimented with various retention policies. FREE ACCESS
EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE
Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.
Digital badges are yours to keep, forever.