java - Editing an external library
问题描述
I have an external library in the project:
The project uses methods from this library
For me, the classes in this library are read-only
I need to change the method logic from an external library a little bit
What and how should I do?
Maybe I should create new class in project with the same logic? (+ my changes)
Maybe other solutions?
解决方案
如果您使用Kotlin
,您可以使用它Extension Function
来扩展类功能而无需extend
它。您使用Java
可以将类和override
或add
方法扩展到它。无需复制/粘贴类即可添加新功能。
推荐阅读
- autodesk-forge - 伪造查看器坐标单元并将其映射到 ThreeJS 场景
- angular - 使用 Phantom JS 测试 ng 项目时出错
- laravel - 带有主管的 Laravel 队列工作者
- android-studio - 'ACTION_MEDIA_SCANNER_SCAN_FILE:String' 已弃用
- spring-boot - 为 Google Cloud Run 外部化应用程序配置
- git - Docker npm install 因本地依赖项而失败,但在命令行中工作
- php - Laravel 以特定格式显示日期
- javascript - 打印时div中的图像在页面之间被切断
- php - 将每个操作记录到数据库 Yii2
- python - 如果我们不止一次地写一个字符串,追加是如何工作的