1. Transient prevents variables modified with this keyword from being serialized. When the object is deserialized, the variable value modified by transient will not be persisted and restored.
2. Transient can only modify variables, but not classes and methods.
Example
public Catalog TreeCatalog(String catalogId) { Catalog catalogNode = findById(catalogId).get(); // 查询当前节点 List<Catalog> catalogList = findChild(catalogId); //查询该节点的所有子节点 for (Catalog child : catalogList) { Catalog catalog = TreeCatalog(child.getCatalog_id()); catalogNode.getChildren().add(catalog); } return catalogNode; }
The above is the detailed content of How to use transient in java. For more information, please follow other related articles on the PHP Chinese website!