Re: A basic question about constants



In article <42e2893e$0$14407$626a14ce@xxxxxxxxxxxx>,
Richard <grin@xxxxxxxx> wrote:

> John B. Matthews a écrit :
> > In article <42e1fbdb$0$29943$636a15ce@xxxxxxxxxxxx>,
> > Richard <grin@xxxxxxxx> wrote:
> >
> >
> >>Hello,
> >>
> >>An extract from the javadoc of javax.sql.rowset.CachedRowSet (an interface):
> >>---
> >>COMMIT_ON_ACCEPT_CHANGES
> >>
> >>static final boolean COMMIT_ON_ACCEPT_CHANGES
> >>
> >>Causes the CachedRowSet object's SyncProvider to commit the changes when
> >>acceptChanges() is called. If set to false, the changes will not be
> >>committed until one of the CachedRowSet interface transaction methods is
> >>called.
> >>
> >>See Also:
> >> commit(), rollback(), Constant Field Values
> >>---
> >>
> >>My basic question is: how is it possible to change the value of a
> >>constant defined in an interface?
> >>
> >>Thanks in advance for your answers.
> >>
> >>Richard
> >
> >
> > AFAIK, you can't: "Every field declaration in the body of an interface
> > is implicitly public, static, and final." [§9.3]

This is true.

> > The value is set by the implementation so you'll know how to handle commits:

My answer here can't be right. The javadoc says "acceptChanges() method
will determine if the COMMIT_ON_ACCEPT_CHANGES is set to true or not,"
implying that it can be changed. But it _can't_ be changed, unless it
implements a different interface.

> But how can the implementation set the value of the constant? It is not
> possible to change the value of a constant and the constant must be
> initialized in the interface.
>
> For example,
>
> public interface I {
> boolean constant = false;
> }
>
> public class AClass implements I {
> static {
> constant = true;
> }
>
> public boolean getConstant() {
> return constant;
> }
> }
>
> does not compile :
> javac AClass.java
> AClass.java:3: cannot assign a value to final variable constant
> constant = true;
>
> There is certainly a thing that I have not understood...

You are correct. I had imagined the implementation somehow "overriding"
the value. That's not Java:-)

> Regards,
>
> Richard
>
> >
> > "Note: The acceptChanges() method will determine if the
> > COMMIT_ON_ACCEPT_CHANGES is set to true or not. If it is set to true,
> > all updates in the synchronization are committed to the data source.
> > Otherwise, the application _must_ explicit[l]y call the commit() or
> > rollback() methods as appropriate." [J2SE 1.5 API]

I wonder now if this is meant to be advice to providers who implement
the CachedRowSet interface. Surely, users don't have to check
COMMIT_ON_ACCEPT_CHANGES to determine if acceptChanges() does the job!
Perhaps COMMIT_ON_ACCEPT_CHANGES being definitively true means that a
conforming implementation does the right thing in acceptChanges(), ie.
call commit if auto_commit is off in the database.

Are you implementing or instantiating?

--
John
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/
.



Relevant Pages

  • Re: HEADSUP: internal network interface changes
    ... >> softcs and replaces them with a struct ifnet pointer which is allocated ... >> longer part of the network interface ABI. ... >> action on the part of the driver without breaking the ABI. ... >> fixed before commit. ...
    (freebsd-current)
  • Re: HEADSUP: internal network interface changes
    ... >> softcs and replaces them with a struct ifnet pointer which is allocated ... >> longer part of the network interface ABI. ... >> action on the part of the driver without breaking the ABI. ... >> fixed before commit. ...
    (freebsd-net)
  • Re: A basic question about constants
    ... Causes the CachedRowSet object's SyncProvider to commit the changes when acceptChangesis called. ... the changes will not be committed until one of the CachedRowSet interface transaction methods is called. ... public boolean getConstant() { ...
    (comp.lang.java.help)
  • Re: [take25 1/6] kevent: Description.
    ... int kevent_commit(int ctl_fd, unsigned int new_tail, ... This approach has the advantage that the commit calls don't have to be ... taken into account and the tail pointer is always short of what it ... I like this interface, although current one does not allow special ...
    (Linux-Kernel)
  • Re: A basic question about constants
    ... > An extract from the javadoc of javax.sql.rowset.CachedRowSet (an interface): ... > committed until one of the CachedRowSet interface transaction methods is ... > commit(), rollback, Constant Field Values ... jmatthews at wright dot edu ...
    (comp.lang.java.help)