The Nested type is private, so GenericNested(Of Nested)
cannot be public. With constructed types, the accessibility is an intersection of the accessibility
of the generic type and the types provided in the argument list.
Constraints
So far, the majority of the generics examples shown involve some sort of collection-style class
that holds a bunch of objects or values of a specific type. But many times, you??™ll need to create
generic types that not only contain instances of various types but also use those objects directly.
For example, suppose you have a generic type that holds instances of arbitrary geometric shapes
that all implement a property named Area. Also, suppose you need the generic type to implement
a property, TotalArea, where all the areas of the contained shapes are accumulated. The
guarantee here is that each geometric shape in the generic container will implement the Area
property. You may be inclined to write code like the following:
Imports System
Imports System.Collections.Generic
Public Interface IShape
ReadOnly Property Area() As Double
End Interface
Public Class Circle
Implements IShape
Private radius As Double
CHAPTER 12 n GENERICS 251
Public Sub New(ByVal radius As Double)
Me.radius = radius
End Sub
Public ReadOnly Property Area() As Double Implements IShape.
Pages:
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411