简体   繁体   中英

Passing parameter to class property in Java

I have this property in a visual basic class. NET 2008, the property in addition to the get and set has a parameter called "pParam. "

Public Property UpdateField(ByVal pParam As String) As String
        Get
            Return Me.idField
        End Get
        Set(ByVal value As String)
            Me.idField = value
            If pParam = "NEW" Then
        // some code here
            End If
        End Set
End Property

which is the equivalent of this in java code?

to use I do the following:

oClass.UpdateField("NEW") = 1850

I have this code in java

public void setUpdateField(String idField) {
    this.idField = idField;
}
public String getUpdateField() {
    return idField;
}

but I need to put the parameter "pParam"

Thanks in advance.

What you've got in the .NET code is an indexer in C# terms. There's no equivalent in Java - you'll just need to take two parameters:

public void setUpdateField(String idField, String pParam) {
    ...
}

Frankly I think it's a little odd that the "getter" in .NET doesn't seem to use the index...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM