java 泛型 引用,Java如何处理对泛型类型的引用

How java stores and deals with generic information with references.

List is a subtype of List>. Please explain above statement. How inheritance works with references to a generic object.

解决方案

The unbounded wildcard type is specified using the wildcard character (?), for example, List. This is called a list of unknown type. There are two scenarios where an unbounded wildcard is a useful approach:

If you are writing a method that can be implemented using functionality provided in the Object class.

When the code is using methods in the generic class that don't depend on the type parameter.

Moving from unbounded(?) to bounded type() is moving away from Generic to Specific entity.

let's go through my own example.

Earth, a planet have Living Things

Animals, Trees are some of the Living things

Humans are animal with 2 legs and 2 hands

Men & Women are two types of humans.

If you have ? in List, you can apply List to Living things. But if you want your list to contain only Humans or Men or Women, you will decide bounded type as per your need.

As you move from generic to specific : List < ? > , List < Living things >, List < Humans >, List< Men >, you are applying more specific things to your entity.

Tree is a Living thing like Human or Men but it can't have 2 legs and 2 hands like Men and it can't think.

You have to decide at which specific level, you want to bind the entity to specific type.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值