Как получить доступ к объекту результата класса данных из запечатанного интерфейсаJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Гость
 Как получить доступ к объекту результата класса данных из запечатанного интерфейса

Сообщение Гость »


Библиотека, которую я использую, использует запечатанный интерфейс и класс данных.
Библиотека:
Это интерфейс из библиотеки:

Код: Выделить всё

public sealed interface TransactionProcessingResult {
public final data class Approved public constructor(authorisationResponse: kotlin.String, authorisationResponseDetails: kotlin.String, receiptData: com...models.ProcessedTransactionReceiptData) : com...models.TransactionProcessingResult {
public final val authorisationResponse: kotlin.String /* compiled code */

public final val authorisationResponseDetails: kotlin.String /* compiled code */

public final val receiptData: com...models.ProcessedTransactionReceiptData /* compiled code */

public final operator fun component1(): kotlin.String { /* compiled code */ }

public final operator fun component3(): com...models.ProcessedTransactionReceiptData { /* compiled code */ }

public open operator fun equals(other: kotlin.Any?): kotlin.Boolean { /* compiled code */ }

public open fun hashCode(): kotlin.Int { /* compiled code */ }

public open fun toString(): kotlin.String { /* compiled code */ }
}

public final data class ApprovedWithSignature public constructor(authorisationResponse: kotlin.String, authorisationResponseDetails: kotlin.String, receiptData: com...models.ProcessedTransactionReceiptData) : com...models.TransactionProcessingResult {
public final val authorisationResponse: kotlin.String /* compiled code */

public final val authorisationResponseDetails: kotlin.String /* compiled code */

public final val receiptData: com...models.ProcessedTransactionReceiptData /* compiled code */

public final operator fun component1(): kotlin.String { /* compiled code */ }

public final operator fun component3(): com...models.ProcessedTransactionReceiptData { /* compiled code */ }

public open operator fun equals(other: kotlin.Any?): kotlin.Boolean { /* compiled code */ }

public open fun hashCode(): kotlin.Int { /* compiled code */ }

public open fun toString(): kotlin.String { /* compiled code */ }
}

public final data class NotApproved public constructor(authorisationResponse: kotlin.String, authorisationResponseDetails: kotlin.String, receiptData: com...models.ProcessedTransactionReceiptData) : com...models.TransactionProcessingResult {
public final val authorisationResponse: kotlin.String /* compiled code */

public final val authorisationResponseDetails: kotlin.String /* compiled code */

public final val receiptData: com...ProcessedTransactionReceiptData /* compiled code */

public final operator fun component1(): kotlin.String { /* compiled code */ }

public final operator fun component3(): com...models.ProcessedTransactionReceiptData { /* compiled code */ }

public open operator fun equals(other: kotlin.Any?): kotlin.Boolean { /* compiled code */ }

public open fun hashCode(): kotlin.Int { /* compiled code */ }

public open fun toString(): kotlin.String { /* compiled code */ }
}
Это метод, который я вызываю из библиотеки.

Код: Выделить всё

public abstract fun startPurchaseTransaction(amount: kotlin.Long, otherAmount: kotlin.Long, currency: java.util.Currency, metadata: kotlin.String, surchargeEnabled: kotlin.Boolean, tippingEnabled: kotlin.Boolean, onSuccess: com...Success, onFailure: com...api.Failure): kotlin.Unit
Использование:

Код: Выделить всё

startPurchaseTransaction(
500,                     //Amount
0,                         //Other amount
nzdCurrency,               //Currency
"This is metadata",        // metadata
false,                     //Tipping disabled
true,                      //Surcharge enabled

//Success
(result) -> {
//how to access result as object/class

},

//Failure
error -> {
//how to access error as object/class

}
);
On success, I want to identify if it was Approved, ApprovedWithSignature or NotAprroved, Is it possible to access/cast result to a data class?, I need to access the result variable so that I can get the details I needed like the authorisationResponseDetails & receiptData.


Источник: https://stackoverflow.com/questions/781 ... -interface
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»