我来自C世界,在那里我们使用"define"来定义不同的返回值,从C函数返回的值,如下所示:
#define RETURN_SUCCESS 0
#define RETURN_ERROR -1
int myFunc()
{
if(...) return(RETURN_SUCCESS);
else if(...) return(RETURN_ERROR);
}
Run Code Online (Sandbox Code Playgroud)
这是如何在Java中以正确的方式完成的?
假设我有:
public MyObject findMyObject()
{
MyObject tempObject = search();
if( tempObject.type == myType )
{
return tempObject;
}
else
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
可以回来null吗?
有没有更合适的方法呢?
我正在为我的Web UI项目使用PrimeFaces UI库.
我有一个manage_watchfolder.xhtml有按钮的页面,这个按钮启动一个对话框:
<p:commandButton value="Add" oncomplete="dlgEditWF.show()"
update=":editWFForm" process="@none"/>
Run Code Online (Sandbox Code Playgroud)
在这个相同的文件中我dlgEditWF包括edit_watchfolder.xhtml:
<p:dialog id="editDialog" widgetVar="dlgEditWF" modal="true"
resizable="true" onShow="showHideActionLocation();">
<ui:include src="edit/edit_watchfolder.xhtml"/>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
问题是,我不希望edit_watchfolder.xhtml被加载单击该按钮之前.但是,edit_watchfolder.xhtml在manage_watchfolder.xhtml创建的同一时刻"加载" .因此,所有调用的bean edit_watchfolder.xhtml都被创建,初始化等,甚至用户也许永远不会真正点击按钮.这会产生大量开销,并使执行变慢.
我可以避免这个吗?
我在C代码中有一些冗余,我想避免.
// Q15 macros
#define SCALE_FACTOR_Q15 ( 0x00008000UL )
#define Q15_MAX ( 0x00007FFFUL )
#define f32_Q15_x(x) ( (f32)(int) ( (float)(x)*(float)SCALE_FACTOR_Q15 ) )
#define f32_Q15_MAX ( (f32) ( Q15_MAX ) )
// etc...
// Q31 macros
#define SCALE_FACTOR_Q31 ( 0x80000000UL )
#define Q31_MAX ( 0x7FFFFFFFUL )
#define f32_Q31_x(x) ( (f32)(int) ( (float)(x)*(float)SCALE_FACTOR_Q31 ) )
#define f32_Q31_MAX ( (f32) ( Q31_MAX ) )
// etc...
Run Code Online (Sandbox Code Playgroud)
现在我需要做同样的代码和平Q25,并且将来可能对其他人来说Qx,x在范围内[1,63].
我怎么能避免为每个单独写这个Qx?
我有一个64位数字,写成两个32位无条件的整数:unsigned int[2].unsigned int[0]是MSB,unsigned int[1]是LSB.我怎么把它转换成double?
double d_from_u2(unsigned int*);
我从Python调用exe工具:
args = '-i' + inputFile
cl = ['info.exe', args]
subprocess.call(cl)
Run Code Online (Sandbox Code Playgroud)
我如何将info.exe的输出重定向到out.txt?
#define DECLARE_TYPE(T) \
typedef struct \
{ \
float value; \
int scale; \
} ae_T##_t;
DECLARE_TYPE(Q25);
Run Code Online (Sandbox Code Playgroud)
这应该创建类型ae_Q25_t,但它不起作用.
如何改写?
#define _GNU_SOURCE\n\n#include <errno.h>\n#include <getopt.h>\n#include <stdarg.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n#include <inttypes.h>\n\nstatic int mylog(const char *format, ...)\n{\n va_list args;\n char *str = NULL;\n\n va_start(args, format);\n vasprintf(&str, format, args);\n va_end(args);\n\n fprintf(stdout, "Test >> %s", str);\n\n free(str);\n return 0;\n}\n\nint main(int argc, char *argv[])\n{\n //...\n}\nRun Code Online (Sandbox Code Playgroud)\nwarning: implicit declaration of function \xe2\x80\x98vasprintf\xe2\x80\x99; did you mean \xe2\x80\x98vsprintf\xe2\x80\x99? [-Wimplicit-function-declaration]
为什么编译器会发出警告vasprintf?
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
我有一个很大的html页面,需要大量滚动.我希望<div>浏览器窗口显示一个绝对的元素,这样无论我在哪里滚动页面,它总是可见的.
我尝试将css用于div元素,position: absolute;但在这种情况下它没有帮助.
怎么做到呢?
有没有更多的“ C ++风格”来编写更改现有数组的方法?
void Util::sevenColors( const float* color1, float* color2 , unsigned int size )
{
for( unsigned int i=0; i<size; i++ )
{
color2[i] = color1[i] * 7.0f;
}
}
Run Code Online (Sandbox Code Playgroud) 在x86上测试一些整数乘法。
int32_t a = 2097152;
int64_t b = a * a;
Run Code Online (Sandbox Code Playgroud)
为何上述b计算结果为零?