Mapstruct:将多个源对象映射到子对象(Mapstruct: Mapping multiple source objects to subobjects)
给出一组四个对象,如:
A{String one, B b} B{String two, String three} C{String one, String two} D{String three}
我希望生成如下映射:
A cAndDToA(C c , D d);
我目前无法找到一种方法来填充A中的B对象与来自C和D的数据。
有没有人知道这个问题的解决方案,或者有更好的方法?
Given a set of four objects like:
A{String one, B b} B{String two, String three} C{String one, String two} D{String three}
I wish to generate a mapping like:
A cAndDToA(C c , D d);
I cannot currently find a way to populate the B object inside of A with data from both C and D.
Does anyone know a solution to this issue, or have a better approach?
原文:https://stackoverflow.com/questions/35706928
最满意答案
此检查由gcc编译器处理,特别是对于scanf / printf函数。
这是一个常见错误,值得为编译器添加特殊案例代码以实现这些功能。
请参阅GCC -WFormat标志: http ://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html
-Wformat:检查对printf和scanf等的调用,以确保提供的参数具有适合指定格式字符串的类型,并且格式字符串中指定的转换是有意义的。 这包括标准函数,以及printf,scanf,strftime和strfmon(X / Open扩展,而不是C标准)系列中格式属性(参见函数属性)指定的其他函数。
所有编译器都没有实现这些检查,因此肯定不能依赖它们。
使用GCC,您可以使用函数属性 'format'和'format-arg'告诉编译器对您的函数应用相同的检查。
format(archetype,string-index,first-to-check)format属性指定函数采用printf,scanf,strftime或strfmon样式参数,这些参数应根据格式字符串进行类型检查。 例如,声明:
extern int my_printf (void *my_object, const char *my_format, ...) __attribute__ ((format (printf, 2, 3)));
...导致编译器检查对my_printf的调用中的参数,以便与printf样式格式字符串参数my_format保持一致。
This check is handled by the gcc compiler, specifically for scanf/printf functions.
It's such a common error that it's worth adding special case code to the compiler for these functions.
see the GCC -WFormat flag here: http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html
-Wformat : Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense. This includes standard functions, and others specified by format attributes (see Function Attributes), in the printf, scanf, strftime and strfmon (an X/Open extension, not in the C standard) families.
These checks are not implemented by all compilers, so it's certainly not something to rely on.
With GCC you can use Function Attributes 'format' and 'format-arg' to tell the compiler to apply the same checks to your functions.
format (archetype, string-index, first-to-check) The format attribute specifies that a function takes printf, scanf, strftime or strfmon style arguments which should be type-checked against a format string. For example, the declaration:
extern int my_printf (void *my_object, const char *my_format, ...) __attribute__ ((format (printf, 2, 3)));
...causes the compiler to check the arguments in calls to my_printf for consistency with the printf style format string argument my_format.
相关问答
更多-
Cabal的main-is选项只告诉Cabal它应该传递给GHC的文件名。 Cabal并不关心它的模块名称。 GHC本身有一个标志,也称为-main-is , 在此记录,它告诉编译器哪个模块具有main功能。 这样可行: executable foo main-is: Foo.hs ghc-options: -main-is Foo 当然Foo.hs应该从module Foo where…开始module Foo where…和导出main 。 像往常一样,模块名称和文件名需要匹配。 这样,所有可 ...
-
我认为,对指针来说也很新颖 nodeType
*current, *trail, *newNode; 在这一点上,newNode没有任何价值,它'点'没有意义 newNode->info = item; 此时你使用newNode的无意义值。 这是你的编译器警告的。 你需要做的就是这样的事情 nodeType *current, *trail, *newNode; newNode = new nodeType (); // make newNode ... -
可能你想要这个? guard let status = dictionary["status"] as? String else { // status does not exist or is not a String } // status is a non-optional String Probably you want this? guard let status = dictionary["status"] as? String else { // status does n ...
-
类似的问题: 什么是结构objc_class的methodLists属性? 根据上面的帖子和本文 ,Apple设计带有双指针的methodLists (对于OBJC2.0来说是相同的)的原因是,简单地说,双指针的结构在运行时将category方法添加到类的方法列表中更快。 由于双指针用于方法列表列表,因此请考虑每个类别都有一个方法列表,并且在运行时将一个或多个类别添加到类中,而不是逐个添加方法时,可以简单地将指针添加到类别方法列表中to methodLists ,它有一个指向每个列表/数组指针的指针。 我不 ...
-
你问题是(并且编译器可能已经发出了关于此的警告)_buffer未初始化,这意味着它指向内存中的某个随机地址 - 因此您的运行时错误。 将您的代码更改为 char buffer [128]; char *_buffer=buffer; 和printf buffer (不是_buffer )。 you problem is (and the compiler has probably already issued a warning about this) _buffer is uninitialized, ...
-
由于没有具体问题,我将就此问题提供一些一般性建议。 看起来你走在正确的轨道上。 您的方法是正确的,您需要遍历语法树并检查每个子表达式,如果您的类型不匹配则失败。 typecheckexp :: [TypeEnv] -> Exp -> Bool typecheckexp types (Add e1 e2) = case (te1, te2) of (Just TyInt, Just TyInt) -> True _ -> False where te1 = getTypeO ...
-
在枚举上提供了类型检查(typechecking provided on enum)[2022-11-15]
由于您手动将3为Color ,编译器将允许您这样做。 如果您尝试使用没有强制转换的普通3初始化变量x ,您将获得诊断。 请注意,枚举可以存储的值范围不受其包含的枚举器的限制。 它是可以存储枚举的所有枚举器值的最小位域的值范围。 也就是说,枚举类型的范围是0..3 : 00 01 10 11 因此值3仍在范围内,因此代码有效。 如果你输出一个4 ,那么结果值将不会被C ++标准指定。 实际上,实现必须为枚举选择基础整数类型。 它可以选择的最小类型是char ,但它仍然能够至少存储高达127值。 但如上所述, ... -
TreeNode
::getInfo的签名返回T ,它是临时的。 您不想尝试分配给它,因为这将不起作用。 相反,调用TreeNode ::setInfo将您的底层Token替换为您想要的那个。 The signature for TreeNode ::getInfo returns T which is a temporary. You don't want to attempt to assign to it, because that will have no effect. Instead ... -
如何使用Smart-Pointers和Subclasses应用类型检查(How to apply typecheck with Smart-Pointers and Subclasses)[2023-10-08]
使用dynamic_cast ,从不输入: if (Van* item = dynamic_cast(a)) { item->doVanThings(); // do van things } //else try other casts 更好的是让多态分化,因为你已经在使用多态: class Auto { public: virtual void doThings() = 0; }; class Van : public Auto { public: void d ... -
针对指针的运行时类型检查(Runtime typechecking for pointers)[2021-11-11]
此检查由gcc编译器处理,特别是对于scanf / printf函数。 这是一个常见错误,值得为编译器添加特殊案例代码以实现这些功能。 请参阅GCC -WFormat标志: http ://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html -Wformat:检查对printf和scanf等的调用,以确保提供的参数具有适合指定格式字符串的类型,并且格式字符串中指定的转换是有意义的。 这包括标准函数,以及printf,scanf,strftime ...