Share via


IInstantSource 介面

定義

提供目前立即的存取權。

[Android.Runtime.Register("java/time/InstantSource", "", "Java.Time.IInstantSourceInvoker", ApiSince=34)]
public interface IInstantSource : Android.Runtime.IJavaObject, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("java/time/InstantSource", "", "Java.Time.IInstantSourceInvoker", ApiSince=34)>]
type IInstantSource = interface
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
衍生
屬性
實作

備註

提供目前立即的存取權。

這個介面的實例可用來存取目前立即的可插入標記法。 例如,可以使用 InstantSource,而不是 System#currentTimeMillis()

此抽象概念的主要目的是允許視需要插入替代的立即來源。 應用程式會使用 物件來取得目前時間,而不是靜態方法。 這可以簡化測試。

因此,此介面不保證結果實際上代表時間行上的目前立即。 相反地,它可讓應用程式提供受控制檢視,以瞭解目前立即的內容。

應用程式的最佳做法是將 傳遞 InstantSource 至任何需要目前立即的方法。 相依性插入架構是達成此目的的其中一種方式:

public class MyBean {
               private InstantSource source;  // dependency inject
               ...
               public void process(Instant endInstant) {
                 if (source.instant().isAfter(endInstant) {
                   ...
                 }
               }
             }

此方法允許替代來源,例如 #fixed(Instant) fixed 或在 #offset(InstantSource, Duration) offset 測試期間使用。

systemFactory 方法會根據最佳的系統時鐘提供來源。 如果有的話,這可以使用 System#currentTimeMillis() 或更高的解析度時鐘。

已在 17 中新增。

java.time.InstantSource JAVA 檔。

此頁面的部分是根據 原始碼專案所建立和共用的工作進行修改,並根據中所述的詞彙使用。

屬性

Handle

取得基礎 Android 物件的 JNI 值。

(繼承來源 IJavaObject)
JniIdentityHashCode

傳回包裝實例的 java.lang.System.identityHashCode() 值。

(繼承來源 IJavaPeerable)
JniManagedPeerState

受控對等的狀態。

(繼承來源 IJavaPeerable)
JniPeerMembers

成員存取和調用支援。

(繼承來源 IJavaPeerable)
PeerReference

JniObjectReference 回已包裝 JAVA 物件實例的 。

(繼承來源 IJavaPeerable)

方法

Disposed()

在處置實例時呼叫。

(繼承來源 IJavaPeerable)
DisposeUnlessReferenced()

如果沒有這個實例的未完成參考,則呼叫 Dispose() ,否則不會執行任何動作。

(繼承來源 IJavaPeerable)
Finalized()

實例完成時呼叫。

(繼承來源 IJavaPeerable)
Fixed(Instant)

取得一律傳回相同立即的來源。

Instant()

取得來源的目前立即。

Millis()

取得來源的目前毫秒立即。

Offset(IInstantSource, Duration)

取得來源,這個來源會從指定的來源傳回已加入指定持續時間的立即。

SetJniIdentityHashCode(Int32)

設定 所 JniIdentityHashCode 傳回的值。

(繼承來源 IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates)

提供目前立即的存取權。

(繼承來源 IJavaPeerable)
SetPeerReference(JniObjectReference)

設定 所 PeerReference 傳回的值。

(繼承來源 IJavaPeerable)
System()

取得使用最佳可用系統時鐘傳回目前立即的來源。

Tick(IInstantSource, Duration)

取得來源,這個來源會從指定的來源截斷到最接近指定持續時間的實例。

UnregisterFromRuntime()

取消註冊此實例,讓執行時間不會從未來的 Java.Interop.JniRuntime+JniValueManager.PeekValue 調用傳回它。

(繼承來源 IJavaPeerable)
WithZone(ZoneId)

傳回具有指定時區的時鐘。

擴充方法

JavaCast<TResult>(IJavaObject)

執行 Android 執行時間檢查的類型轉換。

JavaCast<TResult>(IJavaObject)

提供目前立即的存取權。

GetJniTypeName(IJavaPeerable)

提供目前立即的存取權。

適用於