tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

Strongly typed API for synchronous TDLib method execution in Java interface #2647

Closed vkryl closed 1 year ago

vkryl commented 1 year ago

Client.execute in Java interface is now strongly typed: returned TDLib object type depends on the return type defined in the corresponding Function class.

When TDLib error is occurred, method now throws Client.ExecutionError.

This change adds compile-time protection against return type change and allows using this pattern:

try {
  TdApi.SpecificReturnType result = Client.execute(function);
  // work with strongly typed resultl without casting and type checks
} catch (Client.ExecutionError error) {
  // Handle error
}