Java

本文详细探讨了Java中抽象类与接口的特性及应用,包括构造器的作用、静态类的用途、流操作、命名规范及泛型的重要性。通过对比抽象类与接口,解析super关键字的使用场景,以及何时选择抽象类,为读者提供了深入理解Java面向对象编程的关键概念。

Interface

  • optional parameters

  • interface variables
    interface do not allow instance variables. Only allow static final variables shared by all the instances.

Abstract Class

性质

  1. cannot new a object from a abstract class, constructor of abstract class should be protected
  2. abstract class could have a constructor, when you call sub class’s constructor, jvm will call super class constructor implicitly
  3. abstract class的field不可以是final, 不可以使用@Data or @Value,如果用builder,需要在super class和sub class用@SuperBuilder
  4. 什么时候用abstract class呢?当很多class有shared code的时候
super keyword

利用super,来call abstract class的fields(一般就是hard coded的field), function以及constructor
https://www.javatpoint.com/super-keyword

Why constructor in abstract class

https://stackoverflow.com/questions/2170500/why-do-abstract-classes-in-java-have-constructors

Static Class

只用在nested class里面
https://caveofprogramming.com/java/java-static-class-tutorial.html#:~:text=Static%20classes%20are%20basically%20a,static%20inner%20class%20called%20Wheel.

Stream

link1
link2

Naming

https://stackoverflow.com/questions/6861671/abstract-class-naming-convention
Interface B
abstract AbstractB

access modifier
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

泛型

泛型及其重要性
T和?的区别
大白话
array和generic并不兼容
class aaa 定义这个class可以用泛型
class bbb extends aaa 定义泛型具体是什么

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值