If a judgment or decree of dispossession shall be given in an action for the recovery of possession of premises, or in any real action in favor of a person having a better title thereto, against a person in the possession, held by himself or by his tenant, of any lands, tenements or hereditaments, such person may recover, in a court of competent jurisdiction, compensation for all improvements made by him in good faith on such lands, tenements or hereditaments, prior to his having had notice of such adverse title.
§ 524.160, RSMo