# Preferences Binding and getAndSet()

DevFeed: [Preferences Binding and getAndSet()](<https://devfeed.tech/articles/preferences-binding-and-getandset-19442.md>)

Original publisher: [Read original article](<https://www.codenameone.com/blog/preferences-binding-getandset/>)

Author: Shai Almog

Published: 2018-02-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [CodeName One](<https://devfeed.tech/sources/codename-one.md>)

Topics: [API](<https://devfeed.tech/topics/api.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [blog](<https://devfeed.tech/tags/blog.md>)

## AI overview

This article explains binding property objects to Preferences to retain type safety and describes the getAndSet API, which stores a default value when an entry does not already exist.

## Source excerpt

I added support for binding a property object to Preferences a while back and just didn't have the time to blog about it. I didn't consider it too crucial as the functionality is very simple to figure out, the only difficult part is knowledge of the features existence. Some objects make sense as global objects, we can just use the Preferences API to store that data directly but then we don't have the type safety that property objects bring to the table. That's where the binding of property objects to preferences makes sense. E.g. say we have a global Settings property object we can just bind it to preferences using: