Questions tagged [primitive-types]
Built-in types in any programming language that are defined in an axiomatic way and cannot be divided into other types in the language.
815
questions
0
votes
0
answers
33
views
How to detect auto-boxing and auto-unboxing in Kotlin?
I'm working on a fairly low-level Kotlin JVM library that deals a lot with Bytes and ByteArrays. As I'm dealing with large volumes of data, keeping performance of individual operations high is ...
0
votes
0
answers
20
views
The Concept of Mutable and Immutable in case of Primitive and Reference data types in JS [duplicate]
When we say in JS that primitive values are immutable and reference data type values are mutable. What does it means?
Does it mean that when i write var x=10 an entry containing 10 is created on top ...
-3
votes
1
answer
89
views
NULL as an eighth 'primitive' data type [closed]
A mindless query arising from Java's less known data type 'null'.
Would somebody be able to clarify whether or not 'null' is a literal reserved by the Java language and thus the disparity between it ...
-2
votes
1
answer
55
views
What are rules in casting primitive types in expressions in Java? [duplicate]
I'm trying to figure out why some castings work and why others do not. Can you explain to me why some of these examples work and others don't?
Setup:
I'm using jshell.
byte one = 1;
one ==> 1
...
1
vote
0
answers
54
views
PHP Dependency Injection resolving class with primitive dependencies
I think I'm doing something wrong when trying to write my own Dependency Injection Container. I'm looking at the laravel's one, and it states in a comment
// If the class is null, it means the ...
1
vote
1
answer
64
views
Given an unknown primitive type array in the form of an object, convert it to double array C#
I have searched previous questions here, but nothing quite answers exactly what I am looking for.
I am retrieving an array of primitive type via reflection using PropertyInfo in the form of type ...
1
vote
1
answer
176
views
How to maintain a consistent encryption key in MongoDB client-side field level encryption?
I am using MongoDB client-side field level encryption to encrypt and decrypt data. However, I noticed that every time I execute the program, the primitive binary key changes. This makes it difficult ...
1
vote
4
answers
344
views
Does C have a concept of primitive types and if so what are they?
For example java has 8 primitive types as documented by Oracle.
boolean, byte, short, char, int, long, float, double
C appears to have many, many types, but what if any are considered primitive ...
-1
votes
1
answer
637
views
How to create a Double value from a Float value in Swift
I can't believe that I can't figure this out myself and I also cant find an answer online, but...
I'm working in Swift after a long break working on Dart and Java.
I have a situation where I have ...
0
votes
1
answer
52
views
Is there a way to find all the attributes of a primitive in JavaScript?
In Python, for example, I can use
dir(str)
to find all the attributes and methods of the string data type.
Is there something similar in Javascript?
Just want additional info on JavaScript primitives....
4
votes
1
answer
158
views
why primitive types (eg. number) are assignable to object types(e.g. Number) but not vice versa?
TLDR version:
Why does TypeScript allow the following
let num: Number = new Number(1);
num = 1;
But does not allow this
let num: number = 1;
num = new Number(1)
It is a well-known fact that JS has ...
0
votes
2
answers
57
views
Does the `===` operator in Javascript have separate definitions for primitives vs non-primitives?
With the === operator in Javascript, if it operators on primitives, it returns false if either the values are different or the types are different. If it's operating on non-primitives, it returns ...
0
votes
0
answers
27
views
Javascript: Why does setting two immutable variables equal pass the '===' test, but immutable not? [duplicate]
let a = "hello"
let b = "hello"
console.log(a === b)
returns true, but
let a = ["hello"]
let b = ["hello"]
console.log(a === b)
returns false. Why is this?
0
votes
0
answers
58
views
Javascript: Why don't array methods return a new array?
I understand that the reason methods on strings return a new string is that strings are immutable, so the method can't modify the string you pass to it.
With an array, if you pass it to a method, that ...
0
votes
2
answers
2k
views
Data Type for money in Java
I need to read data from a JSON and there are some money data as shown below:
$234,205,860
I thought to map this data to my DTO class as String, but I am not sure if there is a proper data type in ...
0
votes
0
answers
28
views
Adding Byte and Short [duplicate]
I added a Byte variable to a Short variable, however I had to add (Short) for the line of code to compute. I thought this was not needed as I'm adding a smaller data type to a bigger one. Why is this?
...
0
votes
1
answer
82
views
JavaScript NaN with BibInt return strange types
I can understand why NaN is a 'number' but can someone explain to me why
console.log(typeof 1n+NaN);
console.log(typeof NaN+1n);
There is no such types in documentation.
3
votes
1
answer
264
views
Is there an object wrapper for primitive values that allows mutating them from a lambda?
Consider:
boolean somethingHappened = false;
Runnable doHappen = () -> { somethingHappened = true; }
You cannot do that, because somethingHappened is not final. The rationale is that generally, ...
0
votes
0
answers
32
views
Why if I return primitive long type class in getColumnClass sorting in jtable doesn't work?
I have a problem with sorting primitive long in JTable. I have a class, this class extends AbstractTableModel and overrides method getColumnClass, here is the code of this method:
public Class<?>...
-1
votes
3
answers
323
views
Not able to handle number whose length is more than 10 [duplicate]
I know that max value for int and long are very high but somehow I am not able to handle them in my code. I am getting compilation error in all the scenarios below. Could someone please suggest how I ...
0
votes
0
answers
39
views
Storing primitive vs reference types Javascript && example
I have a very hard time with this topic.
For example at this code:
let test = "primitive";
const arr = [test];
console.log(arr);
test = "changedPrimitive";
console.log(test, arr);
...
1
vote
0
answers
216
views
Why doesn't Project Valhalla introduce mutable structs?
Looks to me like primitive classes could behave more efficiently (at reasonable sizes) if they weren't immutable as currently proposed, but worked more like C structs.
Given this primitive class
...
0
votes
0
answers
167
views
Storing and retrieving a primitive type type(?) in TypeScript
[I'm neither sure how to phrase my Question, nor if what I want to do makes really sense.]
I have an application where a lot of data is stored in a two-dimensional array.
It is (real world) address ...
0
votes
1
answer
38
views
.NET variable memory ALLOCATION versus memory USAGE
This is a relatively simple question, but lately I’ve been looking into Huffman encoding and wanted to ask the pros here at SO.
If I declare a variable as Int32, does it necessarily use all the ...
2
votes
1
answer
81
views
Emplace with primitive types
Since in C++, primitive types destructors do nothing [Do Primitive Types in C++ have destructors?], is it safe to rely on the value of int a to be the same after a call to queue::emplace? Specifically,...
0
votes
0
answers
34
views
Java PriorityQueue behaviour with int[] vs. List<Integer> [duplicate]
While trying to solve this question at stack overflow, I ran into a weird problem: My solution was the same as this solution, except it used a PriorityQueue<List> instead of PriorityQueue<int[...
0
votes
0
answers
30
views
How to increase max integer in javascript? [duplicate]
function sum_of_mul_3_5(n) {
const max_3 = Math.floor((n - 1) / 3);
const max_5 = Math.floor((n - 1) / 5);
const max_15 = Math.floor((n - 1) / 15);
const total_3 = (3 * max_3 * (max_3 + 1)) / ...
1
vote
3
answers
181
views
why ch1 == ch2 is false, doesn't it hold the same char values?
I'm trying to compare two char primitives ch1 and ch2. Both are assigned the value 1 as shown below.
But when compared using the "==" operator it returns false, which I don't understand how ...
0
votes
1
answer
302
views
Field::setLong behave differently with Long and long fields in a class
I have one very strange problem with my code.
When I run it, I get exception:
Exception in thread "main" java.lang.IllegalArgumentException: Can not set java.lang.Long field lesson12....
1
vote
0
answers
554
views
How do I set a Field to null using reflection in java?
This might seem like a stupid question at first, just do field.set(obj, null). But if the field is not an object, but a primitive, this will return an error. What I want is that it "resets" ...
0
votes
1
answer
143
views
Creating HashSet from float[][] array
I just started learning Java and barely know about primitive class and a data type, and I was trying to create a set for every array inside another array. But when I tried doing it the result wasn't a ...
3
votes
1
answer
434
views
Does MATLAB have any set-like datatype?
I am looking for a way to compare finite sequential data with non-deterministic ordering in MATLAB. Basically, what I want is an array, but without imposing an order on the contained elements. If I ...
0
votes
0
answers
60
views
Are return types important for the ide to determine which of the overloaded methods will be called?
In my controller class I have such a method
RequestMapping(value = "/getSomething", method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_A') and hasRole('ROLE_B') " +
...
2
votes
2
answers
1k
views
How can I make jackson throwing error when a value for primitive is not set in json?
Given the code:
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
System.out....
0
votes
0
answers
72
views
Converting Objects to Primitives
Why, when using Symbol.toPrimitive, do we have to return a primitive of the same type as the hint?
For example, when using valueOf() and toString(), we can return for example a string for the "...
-1
votes
2
answers
65
views
Java camparing two numbers, equality for Primitive
Question maybe very simple.
Checked the equality of two Primitive types, then got some mistakes.
One of the double, second one long.
public class TesterPrimitive {
public static void main(String[] ...
0
votes
2
answers
574
views
Cannot return String from @RestController method
I'm working with Spring Boot 2.4.5, MyBatis 3.5.6 and Java 8. When trying to return a String from a @RestController, an obscure error shows up in the returned HttpErrorResponse.
The method tries to ...
4
votes
0
answers
73
views
Purpose of the "offset" parameter in GHC.Prim's (index/read/write)(type)OfAddr# functions
What is the purpose of the "offset" parameter in GHC.Prim's ...OfAddr# functions?
As stated in the documentation this parameter can be used to specify offset in number of elements or bytes ...
-1
votes
1
answer
85
views
How do I merge an arrray of custom Shapes and an Array of strings into a JSON Object using the processing Java Library
currently, I'm trying to make a card game. I'm using primitive shapes in Java and I want to make an object that has about 52 versions of
id:1, suitName: hearts, Cardnum: 1
the error I'm getting when ...
-3
votes
1
answer
54
views
Is {1,4,2} represented by a primitive Type in Java? [closed]
Do Numbers inside such brackets { } always belong to arrays or can it be a primitive Type too?
The exact task is: Decide for the following values (!) whether Java provides primitive data types for ...
1
vote
1
answer
457
views
In Python, Why can't i set attributes to the str class? [duplicate]
class Sample:
pass
sample = Sample()
sample.a = "magic"
print(sample.a)
In the code above, i create an empty class Sample and was able to add set an attribute outside the class ...
1
vote
1
answer
558
views
Primitive Data Types in Dart Lnaguage
My question is short and simple.
when everything is in dart no matter it is a string, boolean, int, float, or char everything is stored in the object in dart language.
so according to the definition ...
0
votes
0
answers
152
views
What is the best way of creating a new primitive data type? [duplicate]
#include <iostream>
typedef uint32_t type1;
struct type2
{
type2(uint32_t i) : i(i) {}
inline operator uint32_t() { return i; }
private:
uint32_t i;
};
void x(uint32_t num) {
...
0
votes
0
answers
19
views
Java Primitive Data Types [duplicate]
I entered the below code:
float myFloatValue1=5/2;
For this I got a message by hovering on 5/2 . It said " '5/2': integer division in floating-point context " and its result gave the value : ...
2
votes
1
answer
363
views
Can I define a new type in julia that acts like primitive data type?
I need to know if there is any way to define a new type in Julia that acts like primitive data type, for example:
struct test
att1::MyType
end
Let's suppose that my MyType is only from 1 to 10. So ...
-1
votes
1
answer
643
views
How to check if an object is a primitive data type in Rust?
I am a C++ developer who is making the transition to Rust, I am looking for something analogous to
bool isPrimitive = std::is_fundamental<varType>. I haven't had much luck in finding a standard ...
0
votes
1
answer
184
views
How to visualize JavaScript wrapper objects?
Lately I read that for every primitive data type, a wrapper object is created. It is this wrapper object what makes it possible to use methods with that data, and that makes sense.
I also read that ...
0
votes
3
answers
63
views
Putting a struct member inside of a separate variable to clean up code and helping me understand how the code would look formatted differently
In C, instead of just listing out a struct variable such as ((struct listing*)p), what kind of primitive type should my variable be in order to hold this and how would it look?
For example, I ...
3
votes
1
answer
154
views
What happens when we treat primitives as objects in JavaScript?
I am learning JS from javascript.info. Now I am currently reading about Methods of primitives.
When we run the following code
let str = 'hello';
alert( str.toUpperCase() ); // HELLO
Internally the ...
0
votes
1
answer
521
views
input mismatch exception while using space in between words
I'm working on a project and I already finished it, I have really simple problem which makes me really confused. I'm trying to ask a user to enter a number from a menu and depending on that different ...