"Effective Java"精读之Lambda和Streams

1. 偏好使用 Lambda 表达式代替匿名类 Lambda 表达式提供了简洁且功能强大的方式来表示行为。它比匿名类更加简洁,并能有效减少冗余代码。 总结: Lambda 表达式使得代码更...

周日 · 2025-01-12 · 3 分钟 · Yuechen

"Effective Java"精读之枚举和注解

1. 使用枚举代替整数常量 枚举比整数常量更加类型安全且可读性更强,能够为每个常量提供额外的功能。通过枚举类型替代整数常量,可以减少代码中的错误并...

周日 · 2025-01-12 · 4 分钟 · Yuechen

"Effective Java"精读之类和接口

1. 尽量减少类和成员的可访问性 类和成员的可访问性应根据实际需求进行设置。将它们的可访问性限制为最小化可以有效减少系统的复杂度并提高安全性。 总结...

周日 · 2025-01-12 · 4 分钟 · Yuechen

"Effective Java"精读之所有对象通用的方法

1. 遵守重写 equals 方法时的通用契约 equals 方法在 Java 中是一个非常重要的函数,它用于比较对象的相等性。在重写 equals 方法时,需要遵守其通用契约:对称性、反射性、传...

周日 · 2025-01-12 · 3 分钟 · Yuechen

"Effective Java"精读之泛型

1. 不要使用原始类型 原始类型无法充分利用泛型的类型安全性和可读性,因此应避免使用原始类型。始终使用参数化类型,以确保类型检查的正确性。 总结: 使...

周六 · 2024-12-28 · 4 分钟 · Yuechen

"Effective Java"精读之创建和销毁对象

1. 考虑使用构造器代替可变参数的工厂方法 在面对多个构造参数时,工厂方法提供了一种灵活的选择,但若可变参数的数量和类型太多时,会使得代码变得难以...

周六 · 2024-12-28 · 4 分钟 · Yuechen

Design Uber

Implement a Cab Booking Application (like Uber) which facilitates: Addition of new cabs to the system. Updating the trips of various customers. Finding the nearest cabs to a location. Design the Uber class: Uber() Initializes the Uber object with 0 cabs and 0 running trips. void addCab(int cabX, int cabY) Adds a cab located at point (cabX, cabY) to the system. Note that multiple cabs can be at the same...

周六 · 2024-12-28 · 5 分钟 · Yuechen

Encode and Decode TinyURL

TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL....

周六 · 2024-12-21 · 7 分钟 · Yuechen