Megosztás a következőn keresztül:


IInstantSource Interface

Definition

Provides access to the current instant.

[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
Derived
Attributes
Implements

Remarks

Provides access to the current instant.

Instances of this interface are used to access a pluggable representation of the current instant. For example, InstantSource can be used instead of System#currentTimeMillis().

The primary purpose of this abstraction is to allow alternate instant sources to be plugged in as and when required. Applications use an object to obtain the current time rather than a static method. This can simplify testing.

As such, this interface does not guarantee the result actually represents the current instant on the time-line. Instead, it allows the application to provide a controlled view as to what the current instant is.

Best practice for applications is to pass an InstantSource into any method that requires the current instant. A dependency injection framework is one way to achieve this:

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

This approach allows an alternative source, such as #fixed(Instant) fixed or #offset(InstantSource, Duration) offset to be used during testing.

The system factory method provides a source based on the best available system clock. This may use System#currentTimeMillis(), or a higher resolution clock if one is available.

Added in 17.

Java documentation for java.time.InstantSource.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
Fixed(Instant)

Obtains a source that always returns the same instant.

Instant()

Gets the current instant of the source.

Millis()

Gets the current millisecond instant of the source.

Offset(IInstantSource, Duration)

Obtains a source that returns instants from the specified source with the specified duration added.

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
System()

Obtains a source that returns the current instant using the best available system clock.

Tick(IInstantSource, Duration)

Obtains a source that returns instants from the specified source truncated to the nearest occurrence of the specified duration.

UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)
WithZone(ZoneId)

Returns a clock with the specified time-zone.

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to