java - Other than foo++, is there any other way to have a variable change value after it is evaluated in one statement? -


let's want write 1 time gate looks this...

int closing = 1; if(closing-- > 0){    //this work once } 

i'm curious if there other mechanism work way (or can made to) potentially overload operator (so speak) behave objects.

i have feeling not doable, i'd curious find out how, if i'm wrong.

sample "wish" code...

class magicobject{    public string oldval = "apple"    public string magicpostevalstring(string newval){       return oldval;       oldval = newval;    } }  magicobject mo = new magicobject();  if(mo.magicposteval("orange").equals("apple")) //this happen once 

notice in magicpostevalstring, value being set after return returns old value prior modifying it.

in essence foo++ doing... evaluates , changes value.

instead of this:

public string magicpostevalstring(string newval){       return oldval;       oldval = newval; } 

you can overwrite oldval , return oldval:

public string magicpostevalstring(string newval){       string tmp = oldval;       oldval = newval;       return tmp; } 

something similar done in java.util.map#put(key, val) method well.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -