Questions tagged [wrapper]

A wrapper is an OOP technique where an object encapsulates (wraps) another object, resource (dynamically allocated memory, OS file/widow handle, socket, thread mutex, etc) or a set of subroutines, hiding/protecting it and providing another (possibly easier to use) interface. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

A Wrapper is an Object which contains another data type, Object, resources, or subroutines for the purpose of encapsulation. The corresponding class of that Wrapper is the wrapper class.

Often when we refer to a wrapper class we often refer to a primitive wrapper class, where instances of that class encapsulate a primitive type.

Many object-oriented languages, such as Java, differentiate between primitive types (such as char) and Objects (such as String), for example that primitive values are passed on by value and are the simplest data types, whereas Objects are passed on by reference and that it includes their own fields and methods. The names of primitive data types are also usually keywords, as opposed to Objects.

In some cases, you may need an instance of a wrapper class for these primitives to perform boxing, treat these primitives as Objects due to OOP reasons, converting a primitive to another Object type, or when using an otherwise primitive value when polymorphism is required. The name of the corresponding primitive wrapper class for a given primitive data type are written in full and follow naming conventions for classes (such as beginning with an uppercase in Java).

Java wrapper classes:

Java offers these wrapper classes which you can use without importing anything. Note that their names begin with an uppercase, and are written in full.

  • Boolean for booleans
  • Character for char
  • Integer for int
  • Long for 64-bit int
  • Double for boudle
  • Byte for byte
  • Short for short
  • Float for float

Tags related to wrapper operations:

Link to Wikipedia page

3619 questions
1
vote
1 answer

How to make a C-DLL wrapped with CFFI to callback python

I am currently trying to wrap a c-dll to controll a camera connected via USB. To grab image data off the camera, the SDK-Provider (Thorlabs) describes two possibilities: Poll the camera in a loop Use callbacks I wrapped the DLL and got the…
1
vote
0 answers

Java casting with primitive wrappers - difference between Java 6 and Java 8

I came across this piece of legacy code (Java 6) (that's simplified version that pinpoints my issue): Object o; o = new Long (3L); Double d; d = (Double) o; This one above is obviously not working as wrappers can be cast only to corresponding…
Jarek Soja
  • 31
  • 6
1
vote
1 answer

How to use c++ .lib(c++ static libraries) file in python

I have some .lib(c++ static library) files and I need to use them in my python program. I know I should use wrapper but I don't know how and have no idea what is that. I searched and found that ctypes python library uses .dll to load the library and…
1
vote
1 answer

Trouble deducing return type for wrapper of member functions

I have a collection of methods with varying signatures which all need the same prefix and postfix code, so I'd like to wrap each of them up neatly. I'm trying to formulate a C++14 variadic template for a generic wrapper to my member functions, and I…
1
vote
1 answer

Example of meaningful container elements

What's the usage of: https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlElementWrapper.html so that a "collection of collections" can be created programatically in a standards acceptable fashion? IBM pdf with…
Thufir
  • 8,216
  • 28
  • 125
  • 273
1
vote
0 answers

CIFS component to wrap around given CRUD web services

I'm pretty sure this is a very particular request, and am slightly proud of it :-) I am looking for a CIFS (Common Internet File System) adapter/layer/wrapper around an existing set of web services, that takes an incoming CIFS request and translates…
chiccodoro
  • 14,407
  • 19
  • 87
  • 130
1
vote
2 answers

Trying to round the edges for a wrapper while keeping border on top of all elements

I'm trying to make a border with rounded edges using custom css for a wrapper. But the z-index always shows it below unless I make the child elements transparent or invisible. Is there anyway to make the border z-index show above, or perhaps add a…
jackson
  • 35
  • 4
1
vote
2 answers

Wrapper or inheritance for file parser in Python

I have a class that implements a parser for a specific file format. I want to add a support for another format. It seems to me that this can be done in two ways: Option 1: Implement several parser methods in the same class, check the file extension…
1
vote
1 answer

Can two numbers be swapped using wrapper class in java without creating any other class?

Here is my code to swap two numbers using wrapper class, i am aware of the fact that java only has pass by value ,so we cannot use use something like a pointer to pass the address of variables.For this i created objects for wrapper class Integer …
1
vote
2 answers

Wrap method implementations of Java interfaces

I have multiple interfaces each defining multiple methods as below: public interface X { void methodX1; void methodX2(String s); } public interface Y { void methodY1; void methodY2(int i); void methodY3(SomeType…
techjourneyman
  • 1,701
  • 3
  • 33
  • 53
1
vote
0 answers

grid alignment - vertical alignment. How to make columns with equal height?

I have a page (see attachment) vertical alignment You can see that the button from the right is not aligned with the other on the left (due to the text above having less lines) How can I make the button go down and be aligned with the one on the…
Alex
  • 11
  • 1
1
vote
1 answer

shell wrapper to restart script based on its output

I've had a bit of shell scripting practice reading piped input from other programs, but am unsure how to approach this problem. THE BACKSTORY A program robinbotter whose internals I can't really fix/modify takes its input from files equities.sym and…
Marcos
  • 4,796
  • 5
  • 40
  • 64
1
vote
1 answer

Wrapping Core Data into Codable structs

I am wrapping Core Data objects into structs to make them Codable. [NB: Before your direct me to writing the swift file for each Core Data class, I would like to say that wrapping the NSManagedObject children result from a conscious choice in…
harrouet
  • 179
  • 8
1
vote
1 answer

C ->Python Import Wrapper Problems

I have defined the name of my wrapper object in my c file blargUtils.c like this (I have defined methods and the lot for it in Blargmethods)... void initBlarg(){ Py_InitModule("Blarg", Blargmethods); } I compiled it like so... blarglib:…
Chris Allen
  • 653
  • 4
  • 9
  • 17
1
vote
5 answers

Convert Alphabetic phone number into just numbers

I am writing a program in Java that needs to take a numeric phone number from the user, for example: 555-GET-FOOD and then print all the numbers, 555-438-3663. I ran into some issues because my program just print one number, not all of it. Also, How…
user10026693