Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strongly typed API for asynchronous TDLib method execution in Java interface #2648

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

vkryl
Copy link
Contributor

@vkryl vkryl commented Oct 26, 2023

This PR includes:

  • Strongly typed Client.send methods, callback parameter type of which is based on the return type declared in TdApi.Function child class, which allow compile-time protection against return type changes, avoiding casts on caller side, etc. Weakly typed send methods remain unchanged for compatibility purposes.
  • Client.send method without any callbacks. The only reason for it is because client.send(function, null) will now cause compile error
  • Warning fix for raw parametrized use of TdApi.Function
  • Small documentation fix in Client.java

This allows using the following pattern when executing methods in Java:

client.send(new TdApi.SpecificReturnTypeFunction(), (typedResult, error) -> {
  if (error != null) {
    // handle error
  } else {
    // work with typedResult without any casting
  }
});

vkryl added 5 commits October 26, 2023 16:41
Added new strongly typed methods to Java interface, which allow complie-time protection against function return type changes and avoiding type casting on caller side
When `resultHandler` is null, nothing is called
@vkryl vkryl changed the title Strongly typed asynchronous send methods in Java layer Strongly typed API for asynchronous TDLib method execution in Java interface Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants