Lightweight (static, compile-time) java reflection – enum of fields of class? (for mapping: ORM, http, etc)

is there some type of reflection in Java that is simply an enum of the fields in a class?

All my fields are sitting right there at compile time, so I’m scratching my head over the need for a dynamic reflection approach to simply being able to reference the fields of a class.

  1. Looking to get a set, define a subset of, and filter out some fields from set-of-all

  2. …and probably call some getters/setters generated? by way of an enumeration to reference the field name/type/modifiers).

  3. Anyone know of any compiler flag or, at this point,

  4. an alternative javac? (note, musing the the Java 8 -parameters flag).

  5. also note, not too interested in adding the full Lombok headspace, but I may swoon for this one. Although unlikely, I might even consider a language switch (to a JVM language)

I’m not a ‘language being’, and I know there’s “reasons” (albeit clue me into non hierarchy-composition/dynamic stuff reasons)… but as someone just working on some high up ORM/http mapping stuff… shouldn’t this be (added like a decade ago) ?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class NiceClass {
//* NOTE this is not real java code today - don't copy and paste expecting it to work! */
static {
Set<NiceClass.class.field> allMyFields = NiceClass.class.fieldz.public();
Set<NiceClass.class.field> allMyLocalPublicFields = NiceClass.class.fieldz.local.public();
Set<NiceClass.class.field> allMyLocalPrivateAndLocalProtectedFields = { Sets.union(
NiceClass.class.fieldz.local.private(),
NiceClass.class.fieldz.local.protected())}
Set<NiceClass.class.field> specificFields = { Set.of(NiceClass.class.fields.ONE,
NiceClass.class.fields.THREE,
NiceClass.class.fields.FIVE )}
Set<NiceClass.class.field> allFieldsWithoutLoggerByFieldName = {
NiceClass.class.fieldz.all().stream().filter(s-> s.name != "logger" ).collect(Collectors.toSet()) }
Set<NiceClass.class.field> allFieldsWithoutLoggerByType = {
NiceClass.class.fieldz.all().stream().filter(s-> s.type != Logger.class ).collect(Collectors.toSet())
}
Set<NiceClass.class.field> allNonTransientFields = {
NiceClass.class.fieldz.all().stream().filter(s-> s.modifier != Modifier.transient ).collect(Collectors.toSet())
}
Set<NiceClass.class.field> holyGrailMySerialization = {
allFieldsWithoutLoggerByType.stream().filter(s-> s.access != private &&
! Modifiers.contains(Modifier.transient) &&
! Modifiers.contains(Modifier.volatile) &&
s.type != MyCredentials.class )
.collect(Collectors.toSet())
}
Set<NiceClass.class.field> holyGrailMySerialization = {
holdGrailMySerialization.stream().filter(s-> ! s.annotations.contains(PrivateStuff.class) )
.collect(Collectors.toSet())
}
//and if you give the mouse a cookie...why shouldn't these be easy to "enable"?
public void set(Object.FieldInterface fieldEnum, Object value); //(casting in impl)
//and typesafe...
NiceClass.class.fieldz.stream().filter(
s->s.setterEnabled)
.map(s->s.type)
.collect(Collectors.toSet()).foreach(s->{
<modifiers> void set<s.type>(fieldEnum, value);
}
})
//bonus to figure out how to reduce that param to what's *statically enabled*...
//I know this is wonky looking syntax ( a Set of types allowed in a generic? )
<modifiers> void set<s.type>(Object.FieldInterface<!!Set.contains(NiceClass.class.fieldz.enabled)>) fieldEnum, value);
//Anyways, the possibilties seem endless having this lightweight reflection...
}
</code>
<code>public class NiceClass { //* NOTE this is not real java code today - don't copy and paste expecting it to work! */ static { Set<NiceClass.class.field> allMyFields = NiceClass.class.fieldz.public(); Set<NiceClass.class.field> allMyLocalPublicFields = NiceClass.class.fieldz.local.public(); Set<NiceClass.class.field> allMyLocalPrivateAndLocalProtectedFields = { Sets.union( NiceClass.class.fieldz.local.private(), NiceClass.class.fieldz.local.protected())} Set<NiceClass.class.field> specificFields = { Set.of(NiceClass.class.fields.ONE, NiceClass.class.fields.THREE, NiceClass.class.fields.FIVE )} Set<NiceClass.class.field> allFieldsWithoutLoggerByFieldName = { NiceClass.class.fieldz.all().stream().filter(s-> s.name != "logger" ).collect(Collectors.toSet()) } Set<NiceClass.class.field> allFieldsWithoutLoggerByType = { NiceClass.class.fieldz.all().stream().filter(s-> s.type != Logger.class ).collect(Collectors.toSet()) } Set<NiceClass.class.field> allNonTransientFields = { NiceClass.class.fieldz.all().stream().filter(s-> s.modifier != Modifier.transient ).collect(Collectors.toSet()) } Set<NiceClass.class.field> holyGrailMySerialization = { allFieldsWithoutLoggerByType.stream().filter(s-> s.access != private && ! Modifiers.contains(Modifier.transient) && ! Modifiers.contains(Modifier.volatile) && s.type != MyCredentials.class ) .collect(Collectors.toSet()) } Set<NiceClass.class.field> holyGrailMySerialization = { holdGrailMySerialization.stream().filter(s-> ! s.annotations.contains(PrivateStuff.class) ) .collect(Collectors.toSet()) } //and if you give the mouse a cookie...why shouldn't these be easy to "enable"? public void set(Object.FieldInterface fieldEnum, Object value); //(casting in impl) //and typesafe... NiceClass.class.fieldz.stream().filter( s->s.setterEnabled) .map(s->s.type) .collect(Collectors.toSet()).foreach(s->{ <modifiers> void set<s.type>(fieldEnum, value); } }) //bonus to figure out how to reduce that param to what's *statically enabled*... //I know this is wonky looking syntax ( a Set of types allowed in a generic? ) <modifiers> void set<s.type>(Object.FieldInterface<!!Set.contains(NiceClass.class.fieldz.enabled)>) fieldEnum, value); //Anyways, the possibilties seem endless having this lightweight reflection... } </code>
public class NiceClass {

    //* NOTE this is not real java code today - don't copy and paste expecting it to work! */
    static {

        Set<NiceClass.class.field> allMyFields = NiceClass.class.fieldz.public();
        Set<NiceClass.class.field> allMyLocalPublicFields = NiceClass.class.fieldz.local.public();

        Set<NiceClass.class.field> allMyLocalPrivateAndLocalProtectedFields = { Sets.union(
                                                                NiceClass.class.fieldz.local.private(),
                                                                NiceClass.class.fieldz.local.protected())}

        Set<NiceClass.class.field> specificFields = { Set.of(NiceClass.class.fields.ONE, 
                                                             NiceClass.class.fields.THREE, 
                                                             NiceClass.class.fields.FIVE  )}

        Set<NiceClass.class.field> allFieldsWithoutLoggerByFieldName = { 
            NiceClass.class.fieldz.all().stream().filter(s-> s.name != "logger" ).collect(Collectors.toSet()) }

        Set<NiceClass.class.field> allFieldsWithoutLoggerByType = { 
            NiceClass.class.fieldz.all().stream().filter(s-> s.type != Logger.class ).collect(Collectors.toSet())
        }

        Set<NiceClass.class.field> allNonTransientFields = { 
            NiceClass.class.fieldz.all().stream().filter(s-> s.modifier != Modifier.transient ).collect(Collectors.toSet())
        }

        Set<NiceClass.class.field> holyGrailMySerialization = { 
            allFieldsWithoutLoggerByType.stream().filter(s-> s.access != private && 
                                                             ! Modifiers.contains(Modifier.transient) && 
                                                             ! Modifiers.contains(Modifier.volatile) &&
                                                             s.type != MyCredentials.class )
                                                             .collect(Collectors.toSet())

        }

        Set<NiceClass.class.field> holyGrailMySerialization = { 
            holdGrailMySerialization.stream().filter(s-> ! s.annotations.contains(PrivateStuff.class) )
                                                             .collect(Collectors.toSet())

    }

    //and if you give the mouse a cookie...why shouldn't these be easy to "enable"?

    public void set(Object.FieldInterface fieldEnum, Object value); //(casting in impl) 

    //and typesafe...
    NiceClass.class.fieldz.stream().filter(
            s->s.setterEnabled)
            .map(s->s.type)
            .collect(Collectors.toSet()).foreach(s->{
    
                <modifiers> void set<s.type>(fieldEnum, value);
            }
    })

    //bonus to figure out how to reduce that param to what's *statically enabled*...

    //I know this is wonky looking syntax ( a Set of types allowed in a generic? )
    <modifiers> void set<s.type>(Object.FieldInterface<!!Set.contains(NiceClass.class.fieldz.enabled)>) fieldEnum, value);

    //Anyways, the possibilties seem endless having this lightweight reflection...
    
    
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật